5.c++ program to get 2 integer numbers and display their sum
INPUT:
#include<iostream>
using namespace std;
int main()
{
int n1,n2,sum;
cout<<"\n Enter Number 1:";
cin>>n1;
cout<<"\n Enter Number 2:";
cin>>n2;
sum = n1+n2;
cout<<"\n The Sum of "<<n1<<" and " <<n2<<" is "<<sum<<endl;
}
In the above program, there are three variables declared. n1,n2 and sum. All these three variables are declared as integer types. so, three different integer values can be stored in these variables.
The variable n1 and n2 are used to store the values that are obtained from the user during the execution of the program, whereas the variable sum is used to store the processed (resultant) value.
During the execution of the above program, line numbers 6 and 8 prompt the user to Enter number 1 and number 2.
OUTPUT:
Comments
Post a Comment