Write a C++ statement to accomplish each of the following task:
- Declare variables sum and x to be of type int.
- Initialize variable x to 1.
- Initialize variable sum to 0
- Add variable x to variable sum and assign the result to variable sum.
- Print "The sum is: " followed by the value of variable sum .
Solution
- int sum, x;
- x = 1;
- sum = 0;
- sum += x;
- cout << "The sum is: " << sum << endl;
0 Questions:
Post a Comment