close
1. 題目:
想看看輸出結果是什麼
2. 程式碼
#include <iostream>
using namespace::std;
int main()
{
int power; // declare power
int a = 1; // initialize x
int sum = 0; // initialize sum
while ( a <= 5 ) // loop 5 times
{
power = a * a;
cout << power << endl;
sum += power;
a++;
}
cout << "Total is " << sum << endl;
system("PAUSE");
return 0;
}
3.結果
1
4
9
16
25
"Total is " 55
1到5的數字各自平方後相加
全站熱搜