Euler Problem 1: Multiples of 3 and 5 : C programming solution

Problem Statement :

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.

Solution Approach:

Being the first problem of the series, its quite a simple one. there are many ways to approach this problem.

Most simplest one is to iterate through all the numbers from 3 to 1000 and check if its divisible by 3 or 5. If they are, just add them to the sum.

Solution :

C

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

#include "stdio.h"

#define LIMIT 1000

intmain()

{

intiter=3;

intsum=0;

while(iter<LIMIT)

{

if(!(iter%3)||!(iter%5))

{

sum+=iter;

}

iter++;

}

printf(" Sum is %d \n",sum);

return0;

}

Answer:233168

Let me know your approach you happen to find a better way to solve this using C programming.

Jeswin Augustine

I 'm a computer science graduate from Karunya University and I 'm a developer/designer. Born and brought up in India, I have worked with clients all around the globe.This blog serves as an informal and unorganized repository of things I ’ve worked on in my free time. It is mostly about programming for the web and sometimes for desktop application.