Project Euler:Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

题目要求:求1000以内3或5倍数的和

代码如下:

#include <stdio.h>

int main()
{
    int n = 1000, i;
    long sum = 0;
    for (i = 1; i < n; i++)
        if ((i % 3 == 0) || (i % 5 == 0))
            sum += i;

    printf ("%d", sum);

    return 0;
}

posted @ 2010-10-17 21:55  jeff_nie  阅读(131)  评论(0编辑  收藏  举报