Also, let's take a look at Euler's project exercise question: Question 001

Source: Internet
Author: User

/*
Question 1:
Description:
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.
*/

# Include <stdio. h>
# Include <stdlib. h>

# Define test 1 // test should be considered before programming (Change 1 to 0 at runtime)

# If test
# Define end_num 10 // constant given by the problem
# Define sum 23
# Else
# Define end_num 1000
# Endif

# Define begin_num 1
# Define fac_1 3
# Define fac_2 5

Int sum_of_mul (const int, const INT );

int main (void)
{< br> printf ("the sum of all the multiples" // too long string literal
"of % d or % d below % d ", // you can use this method to "split"
fac_1, fac_2, end_num
);
printf ("is % d. \ n ",
sum_of_mul (begin_num, end_num, fac_1, fac_2)
);


# If test
printf ("= % d \ n", sum );
# else
# endif
system ("pause");
return 0;
}

Int sum_of_mul (const int begin, const int end,
Const int fac1, const int fac2)
{
Int sum = 0;
Int I;
For (I = begin; I <end; I ++)
{
If (I % fac1 = 0 | I % fac2 = 0)
{
Sum + = I;
}
}
Return sum;
}

Refer to blog
Http://www.cnblogs.com/zhouyinhui/archive/2011/01/05/1926769.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.