Data structure problem practice solution: Euler Project

What is the Euler plan?
The Euler Project is a series of questions that challenge mathematics and computer programming. Although mathematical thinking allows you to use more elegant and effective methods, a proficient computer programming skills can help you solve most problems.
I have written a program, but does it take a few days to get an answer?
Of course not! Each problem is designed according to the "one-minute principle", which means that although it may take several hours to design a successful algorithm to deal with more difficult problems, an efficient implementation of the algorithm will allow ordinary computers to one minute Get the answer within.

Topic 1: Find the sum of multiples of 3 and 5 in natural numbers below 1000

Among the natural numbers below 10, 3, 5, 6 and 9 are multiples of 3 or 5. The sum of them is 23. Find the sum of the natural numbers below 1000 that are multiples of 3 or 5.

#include <stdio.h>
int main()
{
    
    
    int sum=0;
    for(int i=3;i<1000;i++)
    {
    
    
        if(i%3==0||i%5==0)
        sum+=i;
    }
   
    printf("%d",sum);
     return 0;
}

Guess you like

Origin blog.csdn.net/qq_43475285/article/details/113357473