Pyramid Problem No. 45
Q. 45 Write a C program to print the following number pyramid or number structure:
1
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8 9Solving in C:#include <stdio.h> int main(){ int row,col; for(row=1; row<=5; row++){ for(col=1; col<=5-row; col++) printf(" ",col); for(col=1; col<=2*row-1; col++) printf("%d ",col); printf("\n"); } return 0; }
Comments
Post a Comment