Advertisement
Divyansh_Chourey

fibonacci series

Mar 30th, 2024
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | Source Code | 0 0
  1. #include<stdio.h>
  2.  
  3. int fibonacii(int n);
  4.  
  5. int main(){
  6.     int number;
  7.     printf("Enter the number: ");
  8.     scanf("%d", &number);
  9.     printf("Fibonacii series upto %dth number is: ", number);
  10.     for (int i=0; i<number; i++){
  11.         printf("%d, ", fibonacii(i));
  12.     }
  13.     return 0;
  14. }
  15.  
  16. int fibonacii(int n){
  17.     if (n==1){
  18.         return 1;
  19.     }
  20.     else if(n==0){
  21.         return 0;
  22.     }
  23.     else{
  24.         return fibonacii(n-1) + fibonacii(n-2);
  25.     }
  26. }
  27. //output: Enter the number: 9
  28. //Fibonacii series upto 9th number is: 0, 1, 1, 2, 3, 5, 8, 13, 21,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement