Euler Problem 2: Even Fibonacci numbers : C Programming Solution

Problem 2:

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

Solution Approach:

Question starts of with introduction to Fibonacci sequence, which by the way, is a very interesting topic and highly encourage you guys to read about it in web whenever you get time.

Idea is to get the “next” element of Fibonacci series by adding the “present” and “previous” element.  When the element is an even number, add to the “sum” variable. Very simple indeed. Give it a try for yourself before checking the problem solution below. Read More…

Categories: Programming

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. Read More…

Categories: Programming Tags: Tags: , , ,