Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int sum=0; //一開始先宣告一個變數儲存總和
- for(int i=1;i<=100;i++) //i從 1 開始遞增,直到100
- {
- if(i%3!=0)//如果i是3的倍數
- {
- cout<<i<<endl;//輸出i
- sum+=i; //將總和加上該數字
- }
- }
- cout<<"1到100不為3倍數的數字總和是"<<sum<<endl; //輸出sum的結果
- return 0;
- }
Add Comment
Please, Sign In to add comment