-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacciNumber.cpp
More file actions
44 lines (36 loc) · 857 Bytes
/
FibonacciNumber.cpp
File metadata and controls
44 lines (36 loc) · 857 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Given a number N, figure out if it is a member of fibonacci series or not.
// Return true if the number is member of fibonacci series else false.
// Fibonacci Series is defined by the recurrence
// F(n) = F(n-1) + F(n-2)
// where F(0) = 0 and F(1) = 1
/* Main Code
#include<iostream>
using namespace std;
#include "Solution.h"
int main(){
int n;
cin >> n ;
if(checkMember(n)){
cout << "true" << endl;
}else{
cout << "false" << endl;
}
}
*/
// Code
bool checkMember(int n){
/* Don't write main().
* Don't read input, it is passed as function argument.
* Return output and don't print it.
* Taking input and printing output is handled automatically.
*/
int a=0, b=1, sum=0;
while (sum<=n){
sum = a+b;
if (sum == n)
return true;
a = b;
b = sum;
}
return false;
}