Pyramid Problem No. 78

Q.78 Print Square star pyramid as:

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

Solving in C:

#include <stdio.h>
    int main(){
        int row,col;
        for(row=1; row<=4; row++){
            for(col=1;col<=7; col++){
                if(row==1 || col==1 || row==4 || col==7) {
                    if((row==1 && col==1) || (row==1 && col==7) || (row==4 && col==1) || (row==4 && col==7) ) printf(" ");
                    else printf("*");
                }
                else printf(" ");
            }
            printf("\n");
        }
        return 0;
    }

Comments

Popular posts from this blog

Pyramid Problem No. 90

Pyramid Problem No. 74

Pyramid Problem No. 85