Skip to content

Instantly share code, notes, and snippets.

@lalabuy948
Created July 9, 2018 14:05
Show Gist options
  • Save lalabuy948/f3f680ec96745b595fef97631dbd348e to your computer and use it in GitHub Desktop.
Save lalabuy948/f3f680ec96745b595fef97631dbd348e to your computer and use it in GitHub Desktop.
Computes the fibonacci nums
#include <stdio.h>
int fibonacci(int n) {
int a = 1, b = 1, next;
for (int i = 0; i < n; i++) {
if(i <= 1) {
next = i;
} else {
next = a + b;
a = b;
b = next;
}
}
return next;
};
int main() {
printf("Please enter the positive integer:");
int n;
while (scanf("%d", &n) != EOF) {
if (n > 0) {
printf("Fibonacci num is: %d", fibonacci(n));
printf("\n");
} else {
printf("Please, enter positive number");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment