[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以内(<1000)的是3和5的倍数的总和。

欧拉项目的第一个,入门呵呵,为了吸引参与者吧。下面是我的解答,我偏向于简单算法,怎么陈述的,怎么写:

#include <stdio.h>
#include <stdlib.h>

double SumAdd(int n)
{
    double sum = 0.0;
    int i;
   
    for(i = 0; i < 1000; i++)
    {
        if((i %3 == 0) ||(i %5 == 0))
        sum += i;       
    }
   
    return sum;
}

int main(int argc, char *argv[])
{
    double sum;
    sum = SumAdd(1000);
    printf("%lf", sum);
 
  system("PAUSE");
  return 0;
}

答完,可以去看看里面的其他参与者的回复,里面真是牛人众多,有用汇编解决的,还有不知道什么语言解决的⊙﹏⊙b汗

你可能感兴趣的:(project)