問題描述
小於10的自然數中有四個數字能除盡3或5(3, 5, 6, 9),它們的和爲23。
請計算所有小於1000的自然數中能除盡3或5的數字的合。然後使用標準輸出cout,輸出你的結果。
輸入格式
無。
輸出格式
一行一個整數,表示你的結果。
#include<stdio.h>
int judge(int x)
{
if(x%3==0||x%5==0)
return x;
return 0;
}
int main()
{
int ans=0;
for(int i=0; i<1000; i++)
{
ans+=judge(i);
}
printf("%d\n",ans);
return 0;
}