Print a block F using hash (#)

SemiColon
By -
1 minute read
2
7.Write a C program to print a block F using hash (#), where the F has a height of
 seven characters and width of six and five characters.

Sample output: 

######
#
#
#####
#
#
#


Solution:

#include <stdio.h>
 int main()
 {
printf("######\n");
printf("#\n");
printf("#\n");
printf("#####\n");
printf("#\n");
printf("#\n");
printf("#\n");

return(0);

}



OR



#include<stdio.h>
int main()
{
    int row,col;

    for(row=7;row>=1;row--){

        for(col=1;col<=6;col++){

        if(row==7 || col==1)

            printf("#");
        }
        for(col=1;col<=4;col++){

        if(row==4)

            printf("#");

        }

            printf("\n");

    }

    return 0;

}







Tags:

Post a Comment

2Comments

  1. An alternative way of doing this
    #include
    int main(){
    int col, row;
    for (row = 7; row >= 1; row--)
    {
    for(col = 1; col <= 5; col++)
    {
    if(row == 7 || row == 5 || col == 1)
    {
    printf ("#");
    }
    }

    printf("\n");

    }

    return 0;

    }

    ReplyDelete
Post a Comment