Write a C program for the following pattern
Sample input : 4 //number of rows to printSample Output :
1
1 2
3 5 8
13 21 34 55
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include<stdio.h> int fib(int k) { if(k==0) { return 0; } if(k==1) { return 1; } else { return (fib(k-1)+fib(k-2)); //recursion } } int main() { int a=1,i,j,n; printf("Enter number of rows to print: "); scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<i+1;j++) { printf("%d\t",fib(a)); a++; } printf("\n"); } return 0; } |
OUTPUT:
0 comments