ad

Wednesday, June 18, 2025

C program to display alphabet pattern T with Asterisk

web designing theory logo

 C program to Print  Alphabet  T  Using star pattern  

Example 


#include <stdio.h>

int main() {
    int a, b;
    int n = 7; // height of the T

    for (a = 0; a < n; a++) {
        for (b = 0;  b< n; b++) {
            // Print * for the top bar and vertical middle bar
            if (a == 0 || b == n / 2)
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }

    return 0;
}


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

Explain Program

Step 1 ]  

 #include <stdio.h>

int main() {

    int a, b;

    int n = 7; 

 height of the T
n is set to 7, which means the height of the "T" will be 7 rows  variable a and b  are use as loop

Step 2 ]  


Outer Loop – Rows

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


This loop iterates from 0 to 6 (total 7 times),

 each iteration representing one row of output.

Step 3]  

Inner Loop – Columns

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


For each row, this loop iterates 7 times (columns from 0 to 6).

Step 4]  

Conditional Statement


        if (a == 0 || b == n / 2) 
            printf("*");
        else
            printf(" ");


a == 0: For the first row, print a * in every column — this forms the top horizontal bar of the "T".

b == n / 2: For all rows, 
print a * in the middle column (
since n = 7, n / 2 = 3) — this forms the vertical bar of the "T".
Else, print a space.

Step 5 ]  

  printf("\n");

Moves the cursor to the next line after printing each row.


Monday, June 2, 2025

c program to display alphabet pattern R with asterisk

 C program to Print  Alphabet  R star pattern 

Star pattern C program to Print  Alphabet  R

Example 


#include <stdio.h>

int main()
{
    int rows;
    printf("Enter Rows = ");
    scanf("%d", &rows);


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



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

Explain Program

Step :1

      #include <stdio.h>

Includes the standard input/output library for functions like printf() and scanf().

Step :2

     int main() {

 Start of the main function where the execution begins.

Step :3

     int rows;

    printf("Enter Rows = ");

    scanf("%d", &rows);

rows: User-defined number of rows for the pattern.

scanf reads the number from the user.

Step :4

      for (int a = 0; a < rows; a++)


Iterates over each row (a from 0 to rows - 1).

Step :5

     for (int b = 0; b < rows; b++)

For each row, prints characters in the columns (b from 0 to rows - 1).


Step :6

      if ((a == 0 || a == rows / 2) && (0 < b < rows - 1))

 When it's the first row (a == 0) or the middle row (a == rows / 2)

 AND column is not at the edges

Then print * to form the top and middle horizontal bars of the 'R'

Step :7

else if ((a != 0) && (b == 0 || (b == rows - 1 && a < rows / 2 )))

Not the first row (a != 0)
AND
First column (b == 0) → draws the left vertical line of 'R'
OR: Last column (b == rows - 1) AND row is in top half → forms top-right vertical for the top semi-circle of 'R'

Step :8

else if (b == a && a >= rows / 2)

  • For rows in the bottom half (a >= rows / 2)
  • And when b == a → diagonal
  • This draws the slanting leg of 'R' from the middle down to the bottom-right.

Step :9

else {

    printf(" ");

}

  • If none of the above conditions are met, print space.

Step :10

printf("\n");

  • Moves to the next line after finishing a row.

return 0;

Program ends 


Star pattern C program to Print  Alphabet  R
Example 

Star pattern C program to Print  Alphabet  R

Related Post :-

C program to print alphabet C star pattern

C program to print-alphabet B star pattern

C program to Print A star pattern Asterisks pattern


C Program to print Alphabet P Pattern

 C program to Print  Alphabet  P star pattern 


Print the alphabet P in star pattern  in c
Example 


#include <stdio.h>

int main()
{
    int a, b;
    int n = 7; // height of P

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

    return 0;
}

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

Explain Program

Step :1

int n = 7;

  • This sets the height of the letter "P" to 7 rows.
  • It also defines the width, as the letter will be constructed in a 7x8 grid (b <= n, so from 0 to 7, 8 columns total).

Step :2

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

  • Loops through each row (a from 0 to 6).
     a represents the current row number

Step :3

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

  • Loop through each column (b from 0 to 7).
  • b represents the current column number.

Step :4

if (

    b == 0 || // Vertical bar on the left

    (a == 0 && b < n) || // Top horizontal bar

    (a == n / 2 && b < n) || // Middle horizontal bar

    (b == n && a != 0 && a <= n / 2) // Right vertical bar of P (only top half)

)

Step :5

(a == 0 && b < n)

  • This prints the top horizontal bar of 'P'.
  • a == 0  only in the top row.
  • b < n limits the stars to the first n columns

Step :6

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

  • This prints the middle horizontal bar of 'P'.
  • n / 2 is 3 (integer division), so this applies to row 3.
  • Again, stars are printed from column 0 to n - 1.

Step :7

 (b == n && a != 0 && a <= n / 2)

  • This prints the right vertical bar of 'P'.
  • b == n ensures it only prints in the last column (b = 7).
  • a != 0 && a <= n / 2 limits this to the top half of the letter, excluding the top row.

  • .

Step :8

else printf(" ");

  • If the condition is not  prints a space.
  • This helps in shaping the letter correctly with spacing.

Step :9

printf("\n");

  • After each row, moves the cursor to the next line.

C program to Print  Alphabet  P star pattern 
Output

C Program to print Alphabet P Pattern

Summary program

b == 0

    Left vertical line

a == 0 && b < n  

   Top horizontal line

a == n/2 && b < n

   Middle horizontal line

b == n && a != 0 && a <= n/2

   Right vertical line (top half

Related Post :-

C program to print alphabet h star

C program to print alphabetG star

C program to print alphabet F star

Sunday, May 25, 2025

c program to display alphabet pattern O with asterisk

 

 C program to Print  Alphabet  O star pattern 

C program to Print  Alphabet  O star pattern 

Example 


#include <stdio.h>

int main()
{
    int a, b;
    int n = 7; // height and width of the O

    for (a = 0; a < n; a++)
{
        for (b = 0; b < n; b++)
{
            // Print * for the boundary of O
            if ((a == 0 || a == n-1) && (b > 0 && b < n-1)
|| (b == 0 || b == n-1) && (a > 0 && a < n-1))
                printf("*");
            else
                printf(" ");
       
}

        printf("\n");

    }

    return 0;
}


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

Explain Program

Step :1

Variable Declaration

int a, b;
int n = 7; // height and width of the O

a and b are loop variables:
a is used to track rows
b is used to track columns
n = 7 sets both the height and width of the "O". So the output will be a 7x7 grid.

Step :2

Outer Loop – Controls Rows


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

 loop Run from a = 0 to a = 6 (7 row total).
Each iteration represents  new row.

Step :3  

Inner Loop – Controls Columns


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

This loop run for each column in the row.
 for each row, it prints 7 characters (b = 0 to b = 6).

Step :4

 Conditional Statement use

if ((a == 0 || a == n-1) && (b > 0 && b < n-1) 
 || (b == 0 || b == n-1) && (a > 0 && a < n-1))
    printf("*");
else
    printf(" ");
Let’s break this condition down:

Step :5

First Part: 

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

Handles top and bottom row, but only middle part
a == 0 → first row (top of the O)
a == n-1 → last row (bottom of the O)
b > 0 && b < n-1 → avoid the corners 

Step :6

This draws the top and bottom horizontal lines of the 'O' (excluding corners).
Second Part:

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

handles the left and right column, but only the middle part


b == 0 → first column (left edge)
b == n-1 → last column (right edge)
a > 0 && a < n-1 → avoid the top and bottom rows

Step :7

This draws the left and right vertical lines of the 'O' (excluding corners).
 Else Case

    printf(" ");

 condition is not met, it prints a space, so the inside of the 'O' is hollow.

Step :8

printf("\n");

After each row is completed, move to  next line.


C program to Print  Alphabet  O star pattern 

Output


C program to Print  Alphabet  O star pattern




Related Post :-


C program to print alphabet g star Pattern

C program to print alphabet f star pattern

c program to display alphabet pattern N with asterisk

 C program to Print  Alphabet  N star pattern 

C program to Print  Alphabet  N star pattern 

Example 


#include <stdio.h>

int main()
{
    int a,b;
    int n = 7; // height of the N (can be adjusted)

    for (a = 0; a < n; a++)
{
        for (b = 0; b < n; b++)
{
            // Print * for the first column, last column, and diagonal
            if (b == 0 || b == n - 1 || b == a)
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }

    return 0;
}


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

Explain Program

Step :1

#include <stdio.h>

This includes the Standard Input Output library. It is necessary to use functions like printf() for output.

Step :2

int main()

This is the main function from where the execution of the program 

Step :3

int a, b;

These are loop variables:

  • a: for controlling rows
  • b: for controlling columns

Step :4

int n = 7;

 defines the height (and width) of the pattern. The 'N' pattern will be print in a 7x7 grid. You can change n to any positive integer to scale the size of the 'N'

Step :5

Outer Loop: 

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

This controls the rows of the pattern.

  • a = 0 to a = 6 ( n = 7)
  • For each value of a, one full line (row) of output is printed

Step :6

Inner Loop:

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

This controls the columns within each row.

  • b = 0 to b = 6 for each row

Step :7

Conditional:

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

This is the heart of the logic. It decides where to print an asterisk *.

  • b == 0: First column → left vertical line of the 'N'
  • b == n - 1: Last column → right vertical line of the 'N'
  • b == a: Diagonal  top-left to bottom-right (row index == column index)

If any of the three conditions is true, print a *. Otherwise, print a space ( ).

Step :8

printf("*"); 


 printf(" ");

  • Print a * when the condition is met (position of vertical or diagonal part of 'N')
  • Print a space otherwise

Step :9

printf("\n");

After each row is completed move courser next line to start the next

C program to Print  Alphabet  N star pattern 

Output

C program to Print  Alphabet  N star pattern

Related Post :-


C program to print alphabet k star Pattern

C program to prin alphabet j star Pattern


Friday, May 23, 2025

c program to display alphabet pattern L with asterisk

                                            C program

C program to Print  Alphabet  L star pattern 

Example 


#include <stdio.h>

int main() {
    int a,b;
    int n = 7; // height of the L

    for (a = 0; a < n; a++)
{
        for (b = 0; b < n; b++)
{
            // Print * for the left vertical line and the bottom horizontal line
            if (b == 0 || (a == n - 1 && b < n))
{
                printf("*");
            } else {
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}


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

Explain Program

Step :1

Header

#include <stdio.h>
  •  standard input-output library use functions like printf().

Step :2

Main Function Declaration

int main() {

  • The entry point of the program. Execution starts 

Step :3

Variable Declarations

int a, b;

int n = 7; // height of the L

  • a and b are loop counters.
  • n is the height of the letter L and also the number of rows in the output

Step :4

Outer Loop 


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

  • Runs from a = 0 to a = 6 
 iteration of this loop correspond to one row of the output

Step :5

Inner Loop (Controls Columns)

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

  • Run  b = 0 to b = 6 (7 iteration).
  • Each iteration of this loop correspond to one column in the current row

Step :6

.Logic to Print 

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


  • b == 0   
  • This is true for the first column in every row, Explanation we print a * in the first column of every row — forming the vertical line of the "L".
  • (a == n - 1 && b < n):
  • This is true only we are on the last row (a == 6) and b < 7 for all columns of the last row.
  • So on the last row, it prints * across the entire row — forming the bottom horizontal line of the "L".

c

Step :7

printf("*");

Prints an asterisk  the condition is true.


Step :8

printf(" ");

Prints a space

Step :9

printf("\n");

  •  cursor to the next line after printing each row.

C program to Print  Alphabet  L star pattern 

Output


C program to Print  Alphabet  L star pattern


Summary

  • Outer loop: controls rows.

  • Inner loop: controls what to print in each column of the row.

  • Two conditions decide where to print *:

    1. First column (b == 0)

    2. Entire last row (a == n - 1)

Related Post :-

c program to print hollow square star