C++ Examples

C++ program for addition of two numbers using functions.

#include <iostream>

using namespace std;

int addTwoNums(int a, int b);

int main()
{
    int x,y,addition;
    //Taking value of first number
    cout<<"Enter first number: ";  
    cin>>x;
    //Taking value of second number
    cout<<"Enter second number: ";
    cin>>y;
    //Calling the function for addition
    addition = addTwoNums(x,y);
    //Displaying the result
    cout<<"The addition of two numbers is: "<<addition;
    
    return 0;
    
}

int addTwoNums(int a, int b){
    return (a+b);
}

Output

Enter first number: 5
Enter second number: 4
The addition of two numbers is: 9
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments