218k views
0 votes
A program to add two numbers in C++

2 Answers

2 votes


\Large \boxed{\sf code}

#include <iostream>

using namespace std;

int main() {

int a = 19;

int b = 114;

int sum = a + b;

cout << sum;

return 0;

}


\Large \boxed{\sf display} \\\\\sf 133


\Large \boxed{\sf explanation}

Declare the variables a, b, and sum as integers.

The sum of a and b is 'sum.'

Display the sum.

Return an integer value.

User Johnnyutts
by
6.0k points
7 votes
I don't know if i understood correctly, but C++ can add numbers by using the + funciton. You could either use:
a = b + c
or
a = a + b
if you want to increment a variable.
User DieKoderin
by
6.5k points