/*
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