Program To Find Sum Of Two Numbers Using Function in CPP

  1. Home
  2. Tutorials
  3. CPP
  4. CPP Programs
  5. Functions
  6. 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

code example to print sum of numbers using function in c++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.

Comments
Login to TRACK of Comments.