Given an integer N, the task is to find the sum of numbers from 1 to N which are in Fibonacci sequence.
First few Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21, 34, ….
Input: N = 5
1 + 1 + 2 + 3 + 5 = 12
Input: N = 10
1 + 1 + 2 + 3 + 5 + 8 = 20
- Loop through all the Fibonacci numbers which are less than N.
- Initialize a sum variable with 0.
- Keep on adding these Fibonacci numbers to get the required sum.
Below is the implementation of the above approach:
- Program for Fibonacci numbers in PL/SQL
- Look-and-Say Sequence
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Find if given number is sum of first n natural numbers
- Find product of prime numbers between 1 to n
- Algorithm to generate positive rational numbers
- Largest of two distinct numbers without using any conditional statements or operators
- Difference between LED and LCD
- Difference between Function and Procedure
- JBIG2 compression
- Difference between Information and Knowledge
- Cloud Deployment Model
- Basics of Input and Output in Windows PowerShell
- Random-Scan Display
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.