Write a C++ program to read two values from user and print there sum.

Q4. Write a C++ program to read two values from user and print there sum.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int value1,value2,sum;

 

clrscr(); //to clear the screen

 

cout<<“\n Enter first value: “;

cin>>value1;

 

cout<<“\n Enter second value: “;

cin>>value2;

 

sum=value1+value2;

cout<<“\n The sum of given numbers is: “<<sum;

 

getch();//holds the screen until a key is pressed

return 0;//makes the main() to finish

}

 

OUTPUT:

Enter first value: 5

 

Enter second value: 6

 

The sum of given numbers is: 11

Leave a Reply

Your email address will not be published. Required fields are marked *