Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int fibonacci(int n){
- if (n == 0 || n == 1) return n;
- else return fibonacci(n - 1) + fibonacci(n - 2); //Recursion until n becomes 0 or 1
- }
- int main(){
- int n;
- printf("Enter a positive number: ");
- scanf("%d", &n);
- if(n > 0) printf("Term number %d is %d.", n, fibonacci(n-1));
- else printf("\nInvalid choice.");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement