(What Does this Program Do?) What does the following program print?
#include<iostream>
using std: : cout;
using std: : endl;
int main()
{
int y; // declare y
int x = 1; // initialize x
int total = 0; // initialize total
while ( x <= 10 ) // loop 10 times
{
y = x * x; // perform calculation
cout << y << endl; // output result
total += y; // add y to total
x++; // increment counter x
} // end while
cout << "Total is " << total << endl; // display result
return 0; // indicate successful termination
} // end main
6
25
36
49
64
#include<iostream>
using std: : cout;
using std: : endl;
int main()
{
int y; // declare y
int x = 1; // initialize x
int total = 0; // initialize total
while ( x <= 10 ) // loop 10 times
{
y = x * x; // perform calculation
cout << y << endl; // output result
total += y; // add y to total
x++; // increment counter x
} // end while
cout << "Total is " << total << endl; // display result
return 0; // indicate successful termination
} // end main
Solution:
14916
25
36
49
64
Post A Comment:
0 comments: