close
題目:計算1加到100
使用while
1. 程式碼
// Calculate the sum of the integers from 1 to 100
#include <iostream>
using namespace::std;
int main()
{
int sum;
int x;
x = 1;
sum = 0;
while ( x < 101 )
{
sum += x;
x++;
}
cout << "The sum is: " << sum << endl;
return 0;
}
2. 顯示結果
The sum is: 5050
文章標籤
全站熱搜
留言列表