C++ Program For Function Declaration and Stack Concepts in Function

Master C++ with Real-time Projects and Kickstart Your Career Start Now!!

Program 1

// Function declaration and definition
#include<iostream>
#define clrscr() system("cls")
using namespace std;

void add();    // declaration
void factorial();
int main()
{
    clrscr();  
    // cout<<"\nFunction call 1"; 
    // add();   // calling
    factorial();
    // cout<<"\nFunction call 2"; 
    // add();
    // cout<<"\nFunction call 3"; 
    // add();
    
    return 0;
}
void factorial()
{
    int n,f=1;
     cout<<"\nEnter a number";
     cin>>n;
     while(n!=0)
     {
        f=f*n;
        n--;
     }
    cout<<"\n Factorial is"<<f;
}
void add()   // definition
{
      int a,b,c;
      cout<<"\nEnter two number";
      cin>>a>>b;
      c=a+b;
      cout<<"\nAddition is"<<c;
      }

Program 2

// Function declaration and definition
#include<iostream>
#define clrscr() system("cls")
using namespace std;
void abc();
void xyz();
int main()
{
       cout<<"\nOne";
       abc();
      cout<<"\nTwo";
      return 0;
}
void abc()
{
        cout<<"\nThree";
        xyz();
        cout<<"\nFour";

}
void xyz()
{
    cout<<"\nFive";
}

 

Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *