gha890826

大一期中考-2

Apr 18th, 2020 (edited)
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int sum=0; //一開始先宣告一個變數儲存總和
  7.     for(int i=1;i<=100;i++) //i從 1 開始遞增,直到100
  8.     {
  9.         if(i%3!=0)//如果i是3的倍數
  10.         {
  11.             cout<<i<<endl;//輸出i
  12.             sum+=i; //將總和加上該數字
  13.         }
  14.     }
  15.     cout<<"1到100不為3倍數的數字總和是"<<sum<<endl; //輸出sum的結果
  16.     return 0;
  17. }
Add Comment
Please, Sign In to add comment