Created
March 6, 2015 22:26
-
-
Save kenprice/85097cf180056af290be to your computer and use it in GitHub Desktop.
fib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <math.h> | |
#include <stdlib.h> | |
#define MAX_FIB 51 | |
unsigned long int fib[MAX_FIB]; | |
void genfib(int maxf){ | |
int i; | |
fib[0] = 1; | |
fib[1] = 1; | |
for (i=2; i < MAX_FIB; i++){ | |
fib[i] = fib[i-1]+fib[i-2]; | |
if (fib[i] > maxf) break; | |
} | |
} | |
void isFibo(int n){ | |
int flag = 0; | |
int i; | |
for (i=0; i < MAX_FIB; i++){ | |
if (n == fib[i]){ | |
flag = 1; | |
break; | |
} | |
if (n < fib[i]) break; | |
} | |
if (flag) | |
printf("IsFibo"); | |
else | |
printf("IsNotFibo"); | |
} | |
int main() { | |
int _t_max; | |
scanf("%d", &_t_max); | |
unsigned long int t[_t_max]; | |
int i, j; | |
int _maxf=0; | |
for (i=0; i<_t_max; i++){ | |
scanf("%d", &t[i]); | |
_maxf = (_maxf < t[i] ? t[i] : _maxf); | |
} | |
genfib(_maxf); | |
for (i=0; i<_t_max; i++){ | |
isFibo(t[i]); | |
if (i != _t_max-1) printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment