ad

Wednesday, April 23, 2025

c program to display alphabet pattern E with asterisk

  C program


C program to Print  Alphabet E star pattern 

Example


#include <stdio.h>

int main() {
    int a,b;
    int height = 7;
    int width = 5;  

    for (a = 0; a < height;a++) {
        for (b = 0; b < width; b++) {
           
            if (b == 0 || (a == 0 || a == height / 2 || a == height - 1))

          printf("*");

        else

          printf(" ");

        }

        printf("\n");
   
}

    return 0;

}

This C Program Print a pattern in the shape of the capital letter I using asterisks "*"

Explain Program

Step :1

#include <stdio.h>

standard input/output library for function printf() and scanf()

Step :2

int main() {

 Start of the main function where the execution begin

Step :3

    int a, b;

    int height = 7;

    int width = 5;

a and b are loop counters.

 height and width define the size of the pattern.

 height = 7: Number of rows.

 width = 5: Number of columns.

 Step :4

    for (a = 0; a < height; a++) {

outer loop run  a = 0 to a = 6 (7 iterations), controlling the rows

Step :5

        for (b = 0; b < width; b++) {

 inner loops run b = 0 to b = 4 (5 iterations), control the column (characters in each row).

 Step :6

            if (b == 0 || (a == 0 || a == height / 2 || a == height - 1))

                printf("*");

            else

                printf(" ");

This condition determines where to print * or a space.

 Step :7

b == 0

prints a vertical line of * in the first column — like the vertical bar of "E".

 a == 0

Top row — prints the top horizontal line.

  a == height / 2

Middle row — prints the middle horizontal line.

  a == height - 1

Bottom row — prints the bottom horizontal line.

Step :8

printf("\n");

 printing all columns of a row, a new line is printed.

Step :9

return 0;

C program to Print  Alphabet E star pattern  

Output 

C program to Print  Alphabet E star pattern

Related Post :-

C program to print alphabet c star


No comments:

Post a Comment