Program To Find Sum Of Two Numbers Using Function in CPP
- Home
- Tutorials
- CPP
- CPP Programs
- Functions
- Program
Source Code
#include <iostream>
using namespace std;
int getSum(int x,int y) {
return x + y;
}
int main(int argc, char** argv) {
int a,b; // variable declaration
// Taking input in variables
cout<<"Enter First Number : ";
cin>>a;
cout<<"Enter Second Number : ";
cin>>b;
cout<<getSum(a,b);
return 0;
}
Output
Working
In this program a function named as getSum is declared with two parameters before main() function. In function declaration we provide parameter list. This function will take two parameters of integer type at the time of function call. As discussed in Functions topic we can use function call in assignment statement as well as in cout statement whenever this has return type except void.