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的數字各自平方後相加

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 布拉怡 的頭像
    布拉怡

    nini的部落格

    布拉怡 發表在 痞客邦 留言(0) 人氣()