Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

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:

C++ Exercises: Add two numbers accept through keyboard

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:

Flowchart: Add two numbers accept through keyboard

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?