Académique Documents
Professionnel Documents
Culture Documents
GeeksforGeeks
A computer science portal for geeks
GeeksQuiz
Login
Home
Algorithms
DS
GATE
Interview Corner
Q&A
C
C++
Java
Books
Contribute
Ask a Q
About
Array
Bit Magic
C/C++
Articles
GFacts
Linked List
MCQ
Misc
Output
String
Tree
Graph
1/9
3/10/2014
This article is contributed by Abhay Rathi. Please write comments if you find anything incorrect, or you want to
share more information about the topic discussed above
http://www.geeksforgeeks.org/check-number-fibonacci-number/
2/9
3/10/2014
Related Tpoics:
Find if two rectangles overlap
Analysis of Algorithm | Set 4 (Solving Recurrences)
Print all possible paths from top left to bottom right of a mXn matrix
Generate all unique partitions of an integer
Russian Peasant Multiplication
Closest Pair of Points | O(nlogn) Implementation
Find the maximum distance covered using n bikes
Given n line segments, find if any two segments intersect
Like
91
Tw eet
Writing code in comment? Please use ideone.com and share the link here.
20 Comments
GeeksforGeeks
Sort by Newest
Login
Share
Favorite
2 months ago
The above program can only give correct results for 1st 22 Fibonacci numbers..
3
Reply Share
Argha Ghosh
5 months ago
i made it in C after see your question,check it and run it @admin and friends
#include"stdio.h"
main(){
int n,a,b,sum,i,k=1,c;
http://www.geeksforgeeks.org/check-number-fibonacci-number/
3/9
3/10/2014
int n,a,b,sum,i,k=1,c;
int p[30];
while(k==1){
a=0;
b=1;
sum=0;
p[0]=0;
p[1]=1;
i=2;
printf("enter the number:-\n");
scanf("%d",&n);
while(sum<=n){
sum=a+b;
a=b;
see more
Reply Share
priya
5 months ago
(*node)->pLeft = NULL;
(*node)->data = i;
(*node)->pRight = NULL;
see more
Reply Share
Sudarshan Singh
5 months ago
4/9
3/10/2014
v3gA
5 months ago
This is not the most efficient algorithm to check whether a given number is a Fibonacci number.
Matrix exponentiation is much faster than this method.
http://www.quora.com/Algorithm...
4
Reply Share
Sumit Kesarwani
rahul
5 months ago
This code is great example why you should think simple. These ideas should only be used if
they optimize your code. But i dont see this property helping in anyway from a programmer's
perspective. Its only increasing the running time and length of the code. Maths is supposed to
make our lives easier not complicate it by giving unproductive results.
Reply Share
devian
rahul
dude...4 lines doesnt mean easier:).we are not here for cramming...calulating
square and all will take time...
Reply Share
sumit
Reply Share
Anonymous
http://www.geeksforgeeks.org/check-number-fibonacci-number/
Reply Share
5/9
3/10/2014
indian
Reply Share
5 months ago
Reply Share
The_Computing_Machine
Reply Share
Matth
rahul
Reply Share
Sandipan Manna
5 months ago
"A number is Fibonacci if and only if one or both of 5n2+4 or 5x2-4 is a perfect square "
Typo : It should be 5n^2-4
Reply Share
GeeksforGeeks
Mod
Destined2workhard
5 months ago
bibhas_abhishek
5 months ago
Reply Share
http://www.geeksforgeeks.org/check-number-fibonacci-number/
6/9
3/10/2014
Subscribe
GeeksforGeeks
Like
Interview Experiences
Advanced Data Structures
Dynamic Programming
Greedy Algorithms
Backtracking
Pattern Searching
Divide & Conquer
Mathematical Algorithms
Recursion
Geometric Algorithms
http://www.geeksforgeeks.org/check-number-fibonacci-number/
7/9
3/10/2014
Popular Posts
All permutations of a given string
Memory Layout of C Programs
Understanding extern keyword in C
Median of two sorted arrays
Tree traversal without recursion and without stack!
Structure Member Alignment, Padding and Data Packing
Intersection point of two Linked Lists
Lowest Common Ancestor in a BST.
Check if a binary tree is BST or not
Sorted Linked List to Balanced BST
660
Subscribe
http://www.geeksforgeeks.org/check-number-fibonacci-number/
8/9
3/10/2014
Recent Comments
kunal
ay is a subsequence.. we are looking for a...
Dynamic Programming | Set 29 (Longest Common Substring) 35 minutes ago
kri
// Arithmetic based method x = x + x; // x...
How to swap two numbers without using a temporary variable? 1 hour ago
vishal
For structures , we can use memcmp memcmp(...
How to swap two numbers without using a temporary variable? 2 hours ago
Nitin Sharma
Mr.Ganesh Ram Sundaram has provided very cool...
Rearrange an array in-place 3 hours ago
jafar
I don't see how that will give us the desired...
Dynamic Programming | Set 27 (Maximum sum rectangle in a 2D matrix) 3 hours ago
jaaaames
the code is for longest contiguous string
Dynamic Programming | Set 29 (Longest Common Substring) 4 hours ago
Random Number
Fibonacci
The N Number
C++ Java
C++ Programming Golden Number
Numbers Number
Code Number
C++ Function
http://www.geeksforgeeks.org/check-number-fibonacci-number/
9/9