Header Ads Widget

Ticker

6/recent/ticker-posts

C++ Program to generate Fibonacci Triangle Coding by Digitalise Data

C++ Program to generate Fibonacci Triangle Coding by Digitalise Data

 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 <iostream.h>
  2. #include <conio.h>
  3. void main()  
  4. {  
  5.   int a=0,b=1,i,c,n,j;    
  6.     cout<<"Enter the limit: ";    
  7.     cin>>n;    
  8.     for(i=1; i<=n; i++)    
  9.     {    
  10.         a=0;    
  11.         b=1;    
  12.         cout<<b<<"\t";   
  13.         for(j=1; j<i; j++)    
  14.         {    
  15.             c=a+b;    
  16.           cout<<c<<"\t";    
  17.             a=b;    
  18.             b=c;  
  19.         }    
  20.         cout<<"\n";    
  21.     }    
  22. getch ();  
  23. }  

Output:

Enter the limit: 10 
  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  
  1       1       2       3       5       8       13      21      34      55

Post a Comment

0 Comments