C Program to Print Right Angle Fibonacci Series Pyramid
C Program to print Right Angle Fibonacci Series Pyramid
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include<stdio.h> int main(void) { int row, column, first_no = 0, second_no = 1, sum = 1; for (row = 1; row <= 4; row++) { for (column = 1; column <= row; column++) { if (row == 1 && column == 1) { printf("0"); continue; } printf("%d\t", sum); //Computes the series sum = first_no + second_no; first_no = second_no; second_no = sum; } printf("\n"); } return 0; } |
Output :
1 2 3 4 |
0 1 1 2 3 5 8 13 21 34 |
Explanation Of C Program :
Note down declaration and initialization of following variables -
1 |
int row, column, first_no = 0, second_no = 1, sum = 1; |
Now we have write two for loops , one as line number and other for printing the numbers in a row.
1 2 3 4 5 6 |
for (row = 1; row <= 4; row++) { for (column = 1; column <= row; column++) { ----- ----- } } |
Print the first Zero directly using printf statement.
1 2 3 4 |
if (row == 1 && column == 1) { printf("0"); continue; } |
Now print the Fibonacci series using nested loop.
1 2 3 |
sum = first_no + second_no; first_no = second_no; second_no = sum; |