C++ Program for How to check if a given number is Fibonacci number? Last Updated : 26 Feb, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a number 'n', how to check if n is a Fibonacci number. First few Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 141, .. Examples : Input : 8 Output : Yes Input : 34 Output : Yes Input : 41 Output : No Following is an interesting property about Fibonacci numbers that can also be used to check if a given number is Fibonacci or not. A number is Fibonacci if and only if one or both of (5*n2 + 4) or (5*n2 - 4) is a perfect square (Source: Wiki). CPP // C++ program to check if x is a perfect square #include <iostream> #include <math.h> using namespace std; // A utility function that returns true if x is perfect square bool isPerfectSquare(int x) { int s = sqrt(x); return (s * s == x); } // Returns true if n is a Fibonacci Number, else false bool isFibonacci(int n) { // n is Fibonacci if one of 5*n*n + 4 or 5*n*n - 4 or both // is a perfect square return isPerfectSquare(5 * n * n + 4) || isPerfectSquare(5 * n * n - 4); } // A utility function to test above functions int main() { for (int i = 1; i <= 10; i++) isFibonacci(i) ? cout << i << " is a Fibonacci Number \n" : cout << i << " is a not Fibonacci Number \n"; return 0; } Output: 1 is a Fibonacci Number 2 is a Fibonacci Number 3 is a Fibonacci Number 4 is a not Fibonacci Number 5 is a Fibonacci Number 6 is a not Fibonacci Number 7 is a not Fibonacci Number 8 is a Fibonacci Number 9 is a not Fibonacci Number 10 is a not Fibonacci Number Time complexity: O(logn) As sqrt() function takes O(logn) time. Auxiliary space: O(1) As constant extra space is used. Please refer complete article on How to check if a given number is Fibonacci number? for more details! C++ Program for Fibonacci Series using Recursion Comment More infoAdvertise with us Next Article C++ Program For Fibonacci Numbers K kartik Follow Improve Article Tags : C++ Practice Tags : CPP Similar Reads C/C++ Program for nth multiple of a number in Fibonacci Series Given two integers n and k. Find position the n'th multiple of K in the Fibonacci series. Examples: Input : k = 2, n = 3 Output : 9 3'rd multiple of 2 in Fibonacci Series is 34 which appears at position 9. Input : k = 4, n = 5 Output : 30 5'th multiple of 4 in Fibonacci Series is 832040 which appear 4 min read C++ Program For Fibonacci Numbers The Fibonacci series is the sequence where each number is the sum of the previous two numbers. The first two numbers of the Fibonacci series are 0 and 1, and they are used to generate the entire series.Examples:Input: 5Output: 5Explanation: As 5 is the 5th Fibonacci number of series 0, 1, 1, 2, 3, 5 5 min read C++ Program To Find Sum of Fibonacci Numbers at Even Indexes Upto N Terms Given a positive integer N, the task is to find the value of F2 + F4 + F6 +.........+ F2n upto N terms where Fi denotes the i-th Fibonacci number.The Fibonacci numbers are the numbers in the following integer sequence. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...... Examples: Input: n = 5 Outpu 4 min read How to check if a given number is Fibonacci number? Given a number ânâ, how to check if n is a Fibonacci number. First few Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, .. Examples :Input : 8Output : YesInput : 34Output : YesInput : 41Output : NoApproach 1:A simple way is to generate Fibonacci numbers until the generated number 15 min read An efficient way to check whether n-th Fibonacci number is multiple of 10 We are given a variable n, we need to find whether Fibonacci number will be a multiple of 10 or not. Examples: Input : 15Output : Yes Input : 17Output : No A Simple Method is to find the nth Fibonacci number and check if it is divisible by 10 or not. C++ // A simple C++ program to check if // n-th F 7 min read Check if a number is Full Fibonacci or not Given a number N, the task is to check if the given number and all its digits are Fibonacci. If so, then the given number is a Full Fibonacci Number, else not.Examples: Input: 13 Output: Yes Explanation: 13 and its digits 1 and 3 are all Fibonacci numbers Input: 34 Output: No Explanation: 4 is not a 7 min read Like