Write a C++ program which define function with no argument and return value.
x = add();
Here we are considering add() function as user defined function which further takes no argument and have an integer value as return type.
Program Code:
#include <iostream>
using namespace std;
// user defined function with return value (int) and have no argument are passed in it from main()
int add()
{
int c, a, b;
cout<<"Enter the value of first number :" ;
cin>>a;
cout<<endl;
cout<<"Enter the value of second number :" ;
cin>>b;
cout<<endl;
cout<<"Enter the value of first number :" ;
cin>>a;
cout<<endl;
cout<<"Enter the value of second number :" ;
cin>>b;
cout<<endl;
c = a + b;
return c;
}
// main() function with user defined function call
int main()
{
int x;
// user defined function call in the main() with no argument passed in it
x = add();
cout<<"Addition of two given number is : ";
cout<<x;
cout<<x;
return 0;
}
The program output is tested on www.jdoodle.com
Output:
Enter number a : 2
Enter number b : 3
Addition of a and b : 5
Thanks
Mukesh Rajput





Post A Comment:
0 comments: