A problem
Lesson 2 of 20 in Coddy's Mathematical Riddles course.
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 (3 + 5 + 6 + 9 = 23).
Find the sum of all the multiples of 3 or 5 below 100, below 1000...
Challenge
EasyWrite a function calc which takes integer N as input and returns the sum of the multiples of 3 or 5 below N .
For example for N=10 the function will return 23 because 3 + 5 + 6 + 9 = 23
Try it yourself
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "solution.h"
int main() {
int n;
if (scanf("%d", &n) != 1) n = 0;
int r = calc(n);
printf("%d\n", r);
return 0;
}