Computer Science, asked by baradisaanvireddy200, 2 months ago

Write a c program given the value of n(n < 10), i.e, the number of lines, print the Fibonacci triangle.
Sample Input and Output-1:
Enter a number : 5
1
1 2
3 5 8
13 21 34 55
89 144 233 377 610
Sample Input and Output-2:
Enter a number : 7
1
1 2
3 5 8
13 21 34 55
89 144 233 377 610
987 1597 2584 4181 6765 10946
17711 28657 46368 75025 121393 196418 317811​

Answers

Answered by aj200260
0

Answer:

#include<bits/stdc++.h>  

using namespace std;  

 

void fib(int f[], int N)  

{  

 

   f[1] = 1;  

   f[2] = 1;  

     

   for (int i = 3; i <= N; i++)  

     

       

       f[i] = f[i - 1] + f[i - 2];  

}  

 

void fiboTriangle(int n)  

{  

   

   int N = n*(n+1)/2;  

   int f[N + 1];  

   fib(f, N);  

     

   

   int fiboNum = 1;  

 

 

   for (int i = 1; i <= n;i++)  

   {  

       

       for (int j = 1;j <= i;j++)  

           cout << f[fiboNum++] << " ";  

             

       cout << endl;  

   }  

}  

   

int main()  

{  

   int n = 5;  

   fiboTriangle(n);  

   return 0;  

}

HOPE IT HELPS

THANK YOU!

Similar questions