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 <iostream>
#include <cmath>
int main()
{
int sum,temp,target,i;
i=temp=3;
sum=0;
target=1000;
while(temp<(target-3))
{
temp=temp+3;
if(temp%5!=0)
{
i = i + temp;
}
}
sum=sum+i;
i=temp=5;
while(temp<(target-5))
{
temp=temp+5;
i=i+temp;
}
sum=sum+i;
std::cout<<sum<<std::endl;
}