CodesJava

Easy learning with example program codes

C program to print Fibonacci Triangle


The below program is to print the Fibonacci Triangle in C using loop.
C program to print Fibonacci Triangle

#include <stdio.h>
#include<stdlib.h>  
 
void main()
{  
int i,j,k,m;
int a= 0, b=2;
 
for(i=1; i<=5; i++)    
{  
printf("%d\t",b);
 
for(k=1; k<i; k++)    
{    
m=a+b;    
printf("%d\t",m);    
a=b;    
b=m;    
}    
printf("\n");    
}    
}

Output

2
2	2
2	4	6
6	10 	16 	26
26	42	68	110	178
Posted in C   
Sign Up/ Sign In
Ask a Question


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki