C Program to generate Fibonacci Triangle


In this program, we are getting input from the user for the limit for fibonacci triangle, and printing the fibonacci series for the given number of times (limit).

Let's see the c example to generate fibonacci triangle.

  1. #include<stdio.h>    
  2. #include<stdlib.h>  
  3. int main(){  
  4.    int a=0,b=1,i,c,n,j;    
  5. system("cls");  
  6.     printf("Enter the limit:");    
  7.     scanf("%d",&n);    
  8.     for(i=1;i<=n;i++)    
  9.     {    
  10.         a=0;    
  11.         b=1;    
  12.         printf("%d\t",b);    
  13.         for(j=1;j<i;j++)    
  14.         {    
  15.             c=a+b;    
  16.             printf("%d\t",c);    
  17.             a=b;    
  18.             b=c;    
  19.     
  20.         }    
  21.         printf("\n");    
  22.     }    
  23. return 0;  
  24. }  

Output:

Enter the limit:9
1
1 1
1 1 2
1 1 2 3
1 1 2 3 5
1 1 2 3 5 8
1 1 2 3 5 8 13
1 1 2 3 5 8 13 21
1 1 2 3 5 8 13 21 34

Enter the limit:5
1
1 1
1 1 2
1 1 2 3
1 1 2 3 5
Previous Post Next Post