C++ Program to add two numbers using the function


In this program, You will learn how to add two numbers using the function in C++.


20 = 10 + 10

40 = 20 + 20


Example: How to add two numbers using the function in C++

Run it Now
#include<iostream>
using namespace std;

int sum(int x, int y) {

   int z;
   z = x + y;
   return z;
}

int main() {

   int x, y, s;
   cout << "Enter 2 Numbers :";
   cin >> x>>y;

   s = sum(x, y);
   cout << "\nThe Sum is :" << s;

   return 0;
}

Output:

Enter 2 Numbers :12 66
The Sum is :78