-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathisFibonaccian.cpp
More file actions
27 lines (21 loc) · 799 Bytes
/
Copy pathisFibonaccian.cpp
File metadata and controls
27 lines (21 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
#include<math.h>
using namespace std;
//checks if it is perfect square or not
bool isSqrt(int num){
int s = sqrt(num);
return(s*s == num);
}
//checks if it the two terms 5n^2 + 4 are perfect squares or not
bool isFibonacci(int n){
return isSqrt(5*n*n + 4) || isSqrt(5*n*n - 4);
}
int main(){
//the main principle behind whether a number is a fibonacci series element or not is,
// say the number is n, it is in fibonacci, if and only if, one or both, (5n^2 + 4) and (5n^2 - 4) are perfect squares.
int number;
cout<<"Enter the number which you want to search inside the series: ";
cin>>number;
isFibonacci(number)? cout<<"Yes the number is present in series." :
cout<<"No, it is not present in the list.";
}