Blog

Addition in C++ programming language.

Computer / Devops / Korsika / Linux / Online Education

Addition in C++ programming language.

Here’s an example of a C++ program that calculates the sum of two numbers:

#include <iostream>
using namespace std; int main() {
int num1, num2, sum;
cout << “Enter two numbers: “;
cin >> num1 >> num2;
sum = num1 + num2;
cout << “The sum is: ” << sum << endl;
return 0;
}

In this program, we first include the iostream library, which allows us to use the input/output functions like cout and cin. Then, we define a main function, which is where the program starts executing.

Inside the main function, we declare three variables: num1, num2, and sum. We use the cout function to display a message asking the user to enter two numbers, and the cin function to read the input from the user.

We then add the two numbers and store the result in the sum variable. Finally, we use the cout function again to display the sum.

You can run this code on any C++ compiler like GCC, CLANG, MSVC. The result of running this code would be to prompt the user to enter two numbers and after entering the numbers it will display the sum of those two numbers.

Leave your thought here

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

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
  • Attributes
  • Custom attributes
  • Custom fields
Click outside to hide the comparison bar
Compare