w3resource

C++ Exercises: Print the sum of two numbers

C++ Basic: Exercise-2 with Solution

Write a program in C++ to print the sum of two numbers.

Visual Presentation:

C++ Exercises: Print the sum of two numbers

Sample Solution:

C++ Code :

#include <iostream> // Including the input-output stream header file

using namespace std; // Using the standard namespace

int main() // Start of the main function
{
    cout << "\n\n Print the sum of two numbers :\n"; // Outputting a message for displaying the sum of two numbers
	cout << "-----------------------------------\n"; // Outputting a separator line
    cout << " The sum of 29 and 30 is : "<< 29+30 <<"\n\n" ; // Calculating and outputting the sum of 29 and 30

} // End of the main function

Sample Output:

 Print the sum of two numbers :                                        
-----------------------------------                                    
 The sum of 29 and 30 is : 59

Flowchart:

Flowchart: Print the sum of two numbers

C++ Code Editor:

Previous: Write a program in C++ to print a welcome text in a separate line.
Next: Write a program in C++ to find Size of fundamental data types.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/cpp-exercises/basic/cpp-basic-exercise-2.php