Project Euler problem:
If we list all the natural numbers below
10
that are multiples of3 or 5
, we get3, 5, 6 and 9
For the fun of it, I decided on giving the problem some additional constraints.
int sum_multiples(long int m1,long int m2,long int lim)
{
long int sum=0;
for(long int i=m1;i((i+m2)/m2)*m2?((i+m2)/m2)*m2:((i+m1)/m1)*m1) sum+=i;
return sum;
}
int main(int argc, char *argv[])
{
printf("Total: %ld \n",sum_multiples(3,5,1000));
return 0;
}