Like fibonacci series

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wuss7
    New Member
    • May 2020
    • 6

    Like fibonacci series

    Please implement following number series, FiboGorki numbers using a recursive function:

    FiboGorki = 1 3 5 9 17 31 57 105 193......

    Starting from the 4th element, each element is a summation of previous 3 numbers.



    Your function prototype should be:

    int FiboGorki(int n)
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Refer the rules regarding posting homework.

    Comment

    • AjayGohil
      New Member
      • Apr 2019
      • 83

      #3
      Hi,

      You can try below code:

      Code:
      #include<stdio.h>    
      void FiboGorki(int n){    
          static int n1=1,n2=3,n3=5,n4;    
          if(n>0){    
               n4 = n1 + n2+n3;    
               n1 = n2;    
               n2 = n3;
               n3=n4;    
               printf("%d ",n4);    
               FiboGorki(n-1);    
          }    
      }    
      int main(){    
          int n;    
          printf("Enter the number of elements: ");    
          scanf("%d",&n);    
          printf("FiboGork Series: ");    
          printf("%d %d%d ",1,3,5);    
          FiboGorki(n-3);//n-3 because 3 numbers are already printed    
        return 0;  
       }

      Comment

      Working...