All for Joomla All for Webmasters

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<conio.h>
  3. void main(void)
  4. {
  5.     int a=0,b=1,i,c,n,j;
  6.     clrscr();
  7.     printf(“Enter the limit:”);
  8.     scanf(“%d”,&n);
  9.     for(i=1;i<=n;i++)
  10.     {
  11.         a=0;
  12.         b=1;
  13.         printf(“%d\t”,b);
  14.         for(j=1;j<i;j++)
  15.         {
  16.             c=a+b;
  17.             printf(“%d\t”,c);
  18.             a=b;
  19.             b=c;
  20.         }
  21.         printf(“\n”);
  22.     }
  23.     getch();
  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
PinIt
submit to reddit

Leave a Reply

Top