Created
November 14, 2011 20:26
-
-
Save ramntry/1365039 to your computer and use it in GitHub Desktop.
Calculate and print fibb.numbers
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> | |
void printFibb(int counter, unsigned long long prevFibb, unsigned long long prevPrevFibb) | |
{ | |
if (prevFibb == 1) | |
{ | |
printf("1 1 "); | |
counter = counter - 2; | |
} | |
if (counter > 0) | |
{ | |
unsigned long long tmp = prevFibb; | |
prevFibb = prevFibb + prevPrevFibb; | |
prevPrevFibb = tmp; | |
printf("%llu ", prevFibb); | |
counter = counter - 1; | |
printFibb(counter, prevFibb, prevPrevFibb); | |
} | |
} | |
int main(void) | |
{ | |
int n = 0; | |
printf("n = "); | |
scanf("%d", &n); | |
if (n > 93) | |
{ | |
printf("Error: unsigned long long overflowed\n Max argument is 93\n"); | |
return 1; | |
} | |
else if (n < 2) | |
{ | |
printf("Argument must be greater than 2\n"); | |
return 2; | |
} | |
printFibb(n, 1, 1); | |
putchar('\n'); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment