Pyramid Problem No. 63

 Q.63 Write a C program to accept the number of rows of pyramid and print the star pyramid as:if entered number by user is 7 then output would be:

*
**
***
****
***
**
*

Solving in C:

#include <stdio.h>
    int main(){
        int row,col,row_count;
        for(row=1,row_count=7; row<=7; row++,row_count--){ //user entered 7 ,that's why row 7
            for(col=1; row<=(7/2.0)+1 && col<=row; col++) printf("*");
            for(col=row_count; row>(7/2.0)+1 && col>=1; col--) printf("*");
            printf("\n");
        }
        return 0;
    }

Comments

Popular posts from this blog

Pyramid Problem No. 90

Pyramid Problem No. 74

Pyramid Problem No. 85