CPP Tutorial

CPP examples programs

CPP program to print Fibonacci Triangle

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

Code:

#include <iostream.h>
using namespace std;
 
int main()
{  
int a,b,i,c,j;    
for(i=1; i<=5; i++)    
{    
a=0;    
b=2;    
cout<<b<<"\t";   
for(j=1; j<i; j++)    
{    
c=a+b;    
cout<<c<<"\t";    
a=b;    
b=c;  
}    
cout<<"\n";    
}    
return 0;  
}

Output

2   
2       2                    
2       2       4                     
2       2       4       6                
2       2       4       6       10