How to C++ Program to Add Two Numbers
Here, you will learn and get the example code of C++ Program to Add Two Numbers using two different methods.
First we will get two numbers from the user as input, calculate the result, and print result as output.
C++ Program to Add Two Numbers
1 2 3 4 5 6 7 8 9 10 11 | #include<iostream> using namespace std; int main() { int n1, n2, sum; cout<<"Enter Two Numbers: "; cin>>n1>>n2; sum = n1+n2; cout<<"\nSum = "<<sum; return 0; } |
Output
C++ Program to Add Two Numbers using Functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include<iostream> using namespace std; int sum(int,int); int main() { int n1, n2, result; cout<<"Enter Two Numbers: "; cin>>n1>>n2; result = sum(n1,n2); cout<<"\nSum = "<<result; return 0; } int sum(int a,int b) { return(a+b); } |
Output
Check out our other C++ programming Examples