這是我的問題...打印總數到n號
從用戶輸入數字n。該程序應輸出從1到n的所有數字的總和,不包括5的倍數。
例如,如果用戶輸入13,則程序應該計算並打印數之和:1 2 3 4 6 7 8 9 11 12 13(注意5,10不包括在總和)
我做了下面的程序,但它不工作.. 任何一個可以幫助我預先感謝您...
#include <iostream>
using namespace std;
int main()
{
int inputnumber = 0;
int sum = 0;
int count= 1;
cout<<"Enter the number to print the SUM : ";
cin>>inputnumber;
while(count<=inputnumber)
{
if (count % 5!=0)
{
sum = sum + count;
}
} count = count +1;
cout<<"the sum of the numbers are : "<<sum;
}
我不承認錯誤「不工作」。 – stark