View on GitHub

marymafa.github.io


layout: post title: Sum All Odd Fibonacci Numbers date: 2017-11-14 —

Sum All Odd Fibonacci Numbers

About Fibonacci Numbers

We were given a positive integer num, that will return sum of all odd fibonacci numbers that are less than or equal to num.

Fibonacci Numbers

Are the numbers in the integer sequwnce called the fibonnaci sequence and characterized by the fact that whatever number after the first two is the sum of the two preceding ones.

My Approach

Method 1

I have created three variables for previous number, current number and result. Because be start counting by zero that’s why my prevous which is first number is zero.

Method 2

In the test statement i said if the current number is divisible by two then the result should be the current number. And if a curent number does not leave a remainder then take that number to current number.

Finally , I did test my code and it returns an accurate results