while語句計算累加,

while語句計算累加1+2+3+…+100\

計算累加1+2+3+…+100\

#include<iostream>
using namespace std;
void main()
{
 int s, i;
 s = 0;
 i = 1;
 while (i <= 100)
     {
      s += i, i++;
     }
 cout << s << endl;
     
}

把100到200之間不能被3整除的數輸出

#include<iostream>
using namespace std;
void main()
{
 int n;
 for (n=100; n<=200; n++)
 {
  if (n%3==0)
   continue;
  cout<< n << ',';
 }
 cout << endl;
}

睡覺覺

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章