#include <iostream> using namespace std; int main(){ int sum1 = 100+50; int sum2 = sum1+250; int sum3 = sum2+sum2; cout<< sum1 << "\n"; cout<< sum2 << "\n"; cout<< sum3 << "\n"; return 0; }
Explanation of the Code
The given C++ code calculates the sum of three numbers and prints the results.
- Initialization of Variables:
sum1
is initialized as the sum of 100 and 50.sum2
is initialized as the sum ofsum1
and 250.sum3
is initialized as the sum ofsum2
andsum2
.Printing the Results:
- The value of
sum1
(150) is printed. - The value of
sum2
(400) is printed. The value of
sum3
(800) is printed.Return Statement:
- The main function returns 0, indicating successful execution of the program.
The code essentially performs arithmetic operations to calculate the sum of the given numbers and then prints the results.
#include <iostream>
using namespace std;
int main() {
int sum1 = 100 + 50;
int sum2 = sum1 + 250;
int sum3 = sum2 + sum2;
cout << sum1 << "\n";
cout << sum2 << "\n";
cout << sum3 << "\n";
return 0;
}