#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"請輸入要累加的底數:";
cin>>a;
b=1;
c=0;
while(b<=a) //while(條件判斷式){......}
{
c+=b;
b++;
}
cout<<"總合="<<c<<endl;
system("pause");
return 0;
}
輸出結果:
請輸入要累加的底數:66
總和=2211
請按任意鍵繼續 . . .
註: int 最多運算32bit,最大值為2147483647~-2147483647,所以此程式迴圈運算有極限值的。
全站熱搜