#include
int sum_of_series(int limit, int difference)
{
int n = 1 + limit / difference; // integer math gives number of terms including term 0
return ((n * (n - 1)) / 2) * difference;
}
int main(void){
int sum_of_series_3 = sum_of_series(999,3);
int sum_of_series_5 = sum_of_series(999,5);
int sum_of_series_15 = sum_of_series(999,15);
int answer = sum_of_series_3 + sum_of_series_5 - sum_of_series_15;
printf("sum of all the multiples of 3 or 5 below 1000\n");
printf("answer = %d 3s=%d 5s=%d 15s=%d\n",answer, sum_of_series_3, sum_of_series_5, sum_of_series_15);
return 0;
}