ad

Sunday, April 27, 2025

c program to display alphabet pattern J with asterisk

 C program

C program to Print  Alphabet  J star pattern 

Example 


#include <stdio.h>

int main()
{
    int a, b;
    int n = 7;
// Height of the J pattern

    for (a = 0; a < n; a++)
{
        for (b = 0; b < n; b++)
{
            // Print the vertical part of J
           
if (b == n / 2 && a != 0 ||
                (a == n - 1 && b <= n / 2) ||
                (a == n - 2 && b == 0))
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }

    return 0;
}


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

Explain Program

Step :1

Header File

#include <stdio.h>

  •  Standard I/O library to use the printf function for output.

Step :2

.Main Function

int main()

entry point of any C program. Execution starts 

Step :3

Variable Declarations

int n = 7; // Height of the J pattern

  • a and b: Loop counters.
  • n = 7: The size of the square grid (7 rows × 7 columns). 

Step :4

Outer Loop – Row

for (a = 0; a < n; a++)

  • Control the rows from a = 0 to a = 6 (7 rows in total).
Each loop iteration correspond to one line of output

Step :5

 Inner Loop – Columns

for (b = 0; b < n; b++)

  • Control the columns from b = 0 to b = 6 
  • Prints either a * or a space " " for each cell.

Step :6

Main Logic – if Condition

if (b == n / 2 && a != 0 ||

    (a == n - 1 && b <= n / 2) ||

    (a == n - 2 && b == 0))

    printf("*");

else

    printf(" ");

analyze each part of this condition

Step :7

 Condition 1:

b == n / 2 && a != 0
  • n / 2 = 7 / 2 = 3 (integer division).
  • This checks:
  • Column 3 (b == 3)
  • For all rows except the first (a != 0)

 Draws the vertical bar of ‘J’, starting from row 1 down to 6 at the center.

Step :8

Condition 2:

a == n - 1 && b <= n / 2

  • a == 6 (bottom row)
  • b <= 3 → columns 0, 1, 2, 3

 bottom horizontal line of 'J'.

Step :9

Condition 3:

a == n - 2 && b == 0

  • a == 5 (second-last row)
  • b == 0 → first column

Add a small hook at the bottom left (curve of ‘J’)

Step :10

7. Line Break

printf("\n");

  • After finishing each row (b loop ends), moves to a new line for the next row 

. Return Statement

return 0;

C program to Print  Alphabet  J star pattern 
Output

C program to Print  Alphabet  J star pattern

Related Post :-


C program to print alphabet G star

Saturday, April 26, 2025

c program to display alphabet pattern H with asterisk

 C Program

C program to Print  Alphabet  H star pattern 

Example:-


#include <stdio.h>

int main()
{
    int a, b;
    int n = 7;
    for (a = 0; a < n; a++)
{
        for (b = 0; b < n;b++)
{
            if (b == 0 || b == n - 1 || a == n / 2)
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }

    return 0;
}

This C Program Print a pattern in the shape of the capital letter H using asterisks (*) 

Explain Program

Step :1

#include <stdio.h>

  • standard input-output library use functions like printf().

Step :2

int main()

  • The entry point of any C program.
Returns an integer 

Step :3

int a, b;

  • These are loop variables used in the nested for loops:
  • a: Controls the rows.
  • b: Controls the columns.

Step :4

int n = 7;

  • n is the dimension of the pattern.
  • The output will be a 7x7 grid 
  • You can modify n to change.

Step :5

for (a = 0; a < n; a++)

  • Outer loop — iterates over rows from 0 to 6 (7 iterations).

Step :6

for (b = 0; b < n; b++)

  • Inner loop — iterates over column from 0 to 6.

Step :7

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

key condition to print the star *:

  • b == 0 → First column (left vertical line)
  • b == n - 1 → Last column (right vertical line)
  • a == n / 2 → Middle row (horizontal bar)

Step :8

printf("*");

 printf(" ");

  • Prints either a star or a space.

Step :9

printf("\n");

  • After each row is complete, this move to the next line.

Step :10

return 0;

C program to Print  Alphabet  H star pattern 

Output:-

C program to Print  Alphabet  H star pattern

Related Post :-

C program to print alphabet b star

C program to Print A star pattern Asterisks pattern


Friday, April 25, 2025

c program to display alphabet pattern G with asterisk

C Program

C program to Print  Alphabet  G star pattern 

Example :-


#include <stdio.h>

int main() {
    int a, b;
    int n = 7;

    for (a = 0; a < n; a++) {
        for (b = 0; b < n; b++) {
           
            if ((a == 0 ||a == n - 1) && b > 0 && b < n - 1)
                printf("*");
           
            else if ((b == 0 && a > 0 && a < n - 1))
                printf("*");
           
            else if ((a == n / 2 && b >= n / 2) || (a >= n / 2 && b == n - 1))
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }

    return 0;
}

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

Explain Program

Step :1

#include <stdio.h>

Includes the standard input-output library to use functions like printf().

Step :2

int main() { ... }

The entry point of the program.

Step :3

int a, b;

Variables a and b are loop counters:

  • a controls rows
  • b controls columns

Step :4

int n = 7;

 dimension of the pattern is 7 × 7.

Step :5

Outer Loops

 for (a = 0; a < n; a++)

loop goes from row 0 to 6 (7 rows in total).

Step :6

Inner Loop: 

for (b = 0; b < n; b++)

inner loop  loop goes from column 0 to 6 

Step :7

First Condition

if ((a == 0 || a == n - 1) && b > 0 && b < n - 1)


  • When the current row is the first (0) or last (6) AND
  • column is not the first or last 

Step :8

Second Condition

else if ((b == 0 && a > 0 && a < n - 1))

  • Column is the first (0) AND
  • Row is between top and bottom (i.e., not row 0 or 6)

Step :9

🔹 Third Condition

else if ((a == n / 2 && b >= n / 2) || (a >= n / 2 && b == n - 1))

(a == n / 2 && b >= n / 2)

  • Row is the middle row 
  • Column is middle or to the right 

Step :10

(a >= n / 2 && b == n - 1)

  • From the middle row down 
  • At the last column

Step :11

 Else Condition

else

    printf(" ");

  • above conditions match, just print a space.

Final Line

printf("\n");

returen 0;

C program to Print  Alphabet  G star pattern 

Output :-


C program to Print  Alphabet  G star pattern

Related Post :-

C program to print alphabet e star

Thursday, April 24, 2025

c program to display alphabet pattern F with asterisk

 C Program

C program to Print  Alphabet  F star pattern 

Example :-



#include <stdio.h>


int main() {
    int a, b;
    int rows = 7;  

    for (a = 0; a < rows; a++) {
        for (b = 0;  b < rows; b++) {
           
        if (a == 0)
          printf("*");
           
            else if (a == rows / 2 && b < rows - 2)
           printf("*");
           
            else if (b == 0)
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }

    return 0;
}


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

Explain Program

Step :1

#include <stdio.h>

Includes the standard input-output library to use functions like printf().

int main() { ... }

.The entry point of the program.

Step :3

int a, b;

Variables a and b are loop counters:

  • a controls rows
  • b controls columns

Step :4

int n = 7;

The dimension of the pattern is 7 × 7.

Step :5

Outer Loop: 

for (a = 0; a < n; a++)

loop goes from row 0 to 6

Step :6

Inner Loop:

 for (b = 0; b < n; b++)

  • loops iterates over each column in the current row, again from b = 0 to b = 6.

Step :7

Conditional Logic Inside Inner Loop:

         if (a == 0)

          printf("*");

  • Top horizontal line: For the first row (a == 0), print * in all columns, making the top border of the pattern.

Step :8

else if (a == rows / 2 && b < rows - 2)

           printf("*");

  • Middle horizontal line:
  • When a == rows / 2 → a == 3 (since rows = 7, rows / 2 = 3 using integer division).
  • This prints * from b = 0 to b = 4 (i.e., 5 stars), because b < rows - 2 → b < 5.
  • row 4 (index 3) gets 5 stars.

Step :9

else if (b == 0)

            printf("*");

  • Left vertical line: In all other rows, print * in the first column (b == 0).

Step :10

        else

            printf(" ");

  • positions print a space ' ', creating the shape of the letter E.

Step :11

        printf("\n");

  • Moves the output to the next line after each row is completed.

 Return Statement:

    return 0;

C program to Print  Alphabet  F star pattern 

Output 

C program to Print  Alphabet  F star pattern

Related Post :-

C program to print alphabet b star

C program to Print A star pattern Asterisks pattern


Wednesday, April 23, 2025

c program to display alphabet pattern I with asterisk

C program 

C program to Print  Alphabet  I star pattern 
Example 



#include <stdio.h>

int main() {
    int a, b;
    int n = 7;  
    // print of the I

    for (a = 0; a < n; a++) {
        for (b = 0; b < n; b++) {
           
            // Print * for the top, middle, and bottom rows
           
            // or the vertical column in the middle
           
            if (b == n / 2 || a == 0 || a == n - 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 n = 7;

a and b are used as loop counters.

 n = 7 means the output  7x7 grid. 7 rows and 7 columns.

Step :4

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

 each row from a = 0 to a = 6 (total 7 iterations).

Step :5

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

Loops through each column for the current row.

b represents the current column number.

Step :6

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

                printf("*");

            } else {

                printf(" ");

            }

a == 0: This is the top row.

 a == n - 1 (which is 6): This is the bottom row.

 b == n / 2 (which is 3): This is the middle column.

Step :7

        printf("\n");

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

Step :8

    return 0;

Step :9


Step :10

C program to Print  Alphabet  I star pattern 

Output


C program to Print  Alphabet  I star pattern

Related Post :-

C program to print hollow full pyramid


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


Tuesday, April 22, 2025

c program to display alphabet pattern D with asterisk

C Program


C program to Print  Alphabet D star pattern 

Example

#include <stdio.h>

int main() {
    int i, j;
    int n = 7;

    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
           
            if (j == 0 ||
                (i == 0 && j < n - 1) ||
                (i == n - 1 && j < n - 1) ||
                (j == n - 1 && i != 0 && i != n - 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

Main Function Start
int main() {

 Start of the main function where the execution begin

 Step :3

Variable Declarations

int i, j;

int n = 7;

i and j are loop control variable

n = 7 specifies the size of the pattern: it will be 7 rows × 7 column.

Step :4

for (i = 0; i < n; i++) {

This loop control the row number (from 0 to 6).

 Run exactly 7 times because n = 7.

Step :5

Inner Loop 

for (j = 0; j < n; j++) {

loop control the column number within each row.

Step :6

if (j == 0 ||

    (i == 0 && j < n - 1) ||

    (i == n - 1 && j < n - 1) ||

    (j == n - 1 && i != 0 && i != n - 1))

    printf("*");

else

    printf(" ");

Step :7

else

    printf(" ");

If none of the above conditions are true, print a space.

Step :8

printf("\n");

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

Step :9

return 0;

C program to Print  Alphabet D star pattern 

Output

c program to display alphabet pattern D with asterisk

Related Post :-

swastik pattern c program