Write a C++ program which define function with argument and a return value.

Here we are considering display() function as user defined function which further takes two number as argument and an integer value as return type.

Program Code:
#include <iostream>
using namespace std;

// user defined function with return value (int) and have two argument of int type


int display(int x, int y) 
int c; 
c = x + y;
return c;

// main() function with user defined function call

int main() 
int a, b, x; 
cout<<"Enter number a : ";
cin>>a;
cout<<endl;
cout<<"Enter number b : ";
cin>>b;
cout<<endl;
// user defined function call in the main() function with two argument in it
x = display(a,b); 
cout<<"Addition of a and b : "<<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
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: