首页 > 代码库 > Multiples of 3 and 5

Multiples of 3 and 5

problem 1:Multiples of 3 and 5

题意:求1000以下3与5的倍数之和

代码如下:

 1 #ifndef PRO1_H_INCLUDED
 2 #define PRO1_H_INCLUDED
 3 
 4 namespace pro1{
 5     int solve(){
 6         int sum=0;
 7         for(int i=1;i<1000;++i)
 8             if(i%3==0||i%5==0)sum+=i;
 9         return sum;
10     }
11 }
12 
13 #endif // PRO1_H_INCLUDED

 

Multiples of 3 and 5