Pyramid Problem No. 87
Q.87 Print following alternative number-star pyramid as:
1 2*2 3*3*3 4*4*4*4 4*4*4*4 3*3*3 2*2 1
Solving in C:#include <stdio.h> int main(){ int row,col; for(row=1; row<=4; row++){ for(col=1; col<=2*row-1; col++){ if(col%2==0) printf("*"); else printf("%d",row); } printf("\n"); } for(row=4; row>=1; row--){ for(col=1; col<=2*row-1; col++){ if(col%2==0) printf("*"); else printf("%d",row); } printf("\n"); } return 0; }
Comments
Post a Comment