C++ Exercises: Add two numbers accept through keyboard
C++ Basic: Exercise-12 with Solution
Write a program in C++ to add two numbers accept through keyboard.
Pictorial Presentation:
Sample Solution:
C++ Code :
#include <iostream>
using namespace std;
int main()
{
int num1, num2, sum;
cout << "\n Sum of two numbers :\n";
cout << "-------------------------\n";
cout << " Input 1st number : ";
cin >> num1 ;
cout << " Input 2nd number : ";
cin >> num2;
sum = num1 + num2;
cout <<" The sum of the numbers is : " << sum << endl;
cout << endl;
return 0;
}
Sample Output:
Sum of two numbers : ------------------------- Input 1st number : 25 Input 2nd number : 39 The sum of the numbers is : 64
Flowchart:
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C++ to print the result of the specified operations.
Next: Write a program in C++ to swap two numbers.
What is the difficulty level of this exercise?