ad

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


C program to Print Alphabet C star pattern

C Program

logo

 C program to Print  Alphabet C 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 || a == rows - 1 || b == 0)
{
             
                if ((a == 0 || a == rows - 1) && b > 4)
                    continue;
                printf("*");
           
} else {

                printf(" ");
            }
        }

        printf("\n");
    }

    return 0;

}

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

Explain Program

Step :1

#include <stdio.h>

 standard input-output library in C, so you can use printf().

Step :2

int main() {

    int a, b;

    int rows = 7;

a and b are loop counters use for iterating through row and columns, respectively.

Step :3

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

This loop controls the vertical position (top to bottom).

Step :4

Inner Loop: 

Controls Columns

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

Controls the horizontal position in each row (left to right).

Step :5

Main Logic for Pattern Drawing

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

condition determines when to print a *:

 a == 0 → Top row (first row)

a == rows - 1 → Bottom row (last row)

 b == 0 → Leftmost column

Step :6

Inner Condition: continue

if ((a == 0 || a == rows - 1) && b > 4)

 top or bottom row, column > 4, then:

Step :7

Space

printf("*");

Print a star if the condition.

Step :8

else {

    printf(" ");

}

condition are not met, print to  the  space.

  printf("\n");

 printing one row,next line.


C program to Print  Alphabet C star pattern 

Output

C program to Print  Alphabet C star pattern


Related Post :-

C Program print Inverted Right Half Pyramid Star Patern


Monday, April 21, 2025

C program to Print Alphabet B star pattern

                                            C Program

C program to Print B star pattern Asterisks pattern 

 Example:-


#include <stdio.h>

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

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

    return 0;
}

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

Explain Program

Step :1

#include <stdio.h>

 standard input/output library for using functions like printf().

Step :2

int main() {

    int a, b;

    int rows = 7;

a and b are loop counters. 

rows = 7 sets the height of the pattern to 7 rows. This will determine how tall the printed "E" is.

Step :3

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

This loops control each row of the output.runs from a = 0 to a = 6

Step :4

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

This loops controls each row of the output. So it runs from a = 0 to a = 6

Step :5

        if (

            b == 0 ||

            (a == 0 && b < 4) ||

            (a == rows / 2 && b < 4) ||

            (a == rows - 1 && b < 4) ||

            (b == 4 && a != 0 && a != rows / 2 && a != rows - 1)

        ) {

            printf("*");

        } else {

            printf(" ");

        }

 b == 0s prints the left vertical line of the "E".

 (a == 0 && b < 4)

draws the top horizontal bar of the "E".

 (a == rows / 2 && b < 4)

 draws the middle horizontal bar.

(a == rows - 1 && b < 4)

 draws the bottom horizontal bar.

 (b == 4 && a != 0 && a != rows / 2 && a != rows - 1)

adds a small vertical extension on the top right.


C program to Print B star pattern Asterisks pattern 

OutPut :-

C program to Print B star pattern Asterisks pattern


Related Post :-

php date time program

Website about us page html and css



Tuesday, April 15, 2025

C program to Print A star pattern Asterisks pattern

 C Program



https://webdesigningtheory.blogspot.com/


C program to Print A star pattern Asterisks pattern 

Example:-


#include <stdio.h>
int main() {
    int no = 7;
    int i, j;
    for (i = 0; i < no; i++)

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

{
              if ((j == 0 || j == no) && i != 0 || (i == 0 && j > 0 && j < no) ||
(i == no / 2))


                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }

     return 0;

    }





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

Explain Program

Step :1

#include <stdio.h>

  • standard input-output library.
  • Required for using printf().

Step :2

. int no = 7;


  • set the number of row (no = 7). 
  • print a 7-line tall pattern, and each line will have up to 8 character (j from 0 to 7).

Step :3

Outer Loop:

 for (i = 0; i < no; i++)

 loop runs  i = 0 to i = 6 (7 iterations) → each iteration prints one row

Step :4

4. Inner Loop: 

for (j = 0; j <= no; j++)

  •  loops run from j = 0 to j = 7 (8 iteration) → each iteration print one character per row (either * or space).

Step :5

if Condition:

if ((j == 0 || j == no) && i != 0 ||

    (i == 0 && j > 0 && j < no) ||

    (i == no / 2))

(j == 0 || j == no) && i != 0

  • Print * at the leftmost (j == 0) and rightmost (j == no) columns, but not on the first row (i != 0).
  • This creates the legs of "A".

(i == 0 && j > 0 && j < no)

  • On the first row (i == 0), print * except for the first and last columns (j > 0 && j < no).
  • This creates the top bar of the "A".

 (i == no / 2)

  • When the row index i equals no / 2 (i.e., middle row — for 7 rows, this is i == 3), print * for all columns.
  • This forms the middle horizontal line of the "A".

Step :6

printf("*"); 

else printf(" ");

  • Based on the if condition above, either print * (when true) or a space (" ") otherwise.

Step :7

7. printf("\n");

  • printed,to the next line.

C program to Print A star pattern Asterisks pattern 

Output :-

C program to Print A star pattern Asterisks pattern


Monday, April 14, 2025

C Program to print Hollow Hourglass pattern

   C  Program

C Program to print Hollow Hourglass pattern 

Example :-


#include <stdio.h>
 
int main()
{
  int i, j, k, rows;
 
  printf("Enter the no. of rows: ");
  scanf("%d", &rows);
 
  printf("Output: \n\n");
 
  for (i = 1; i <= rows; i++)
  {
    for (k = 1; k < i; k++)
      printf(" ");
 
    for (j = i; j <= rows; j++)
      printf("* ");
 
    printf("\n");
  }
 
  for (i = rows - 1; i >= 1; i--)
  {
    for (k = 1; k < i; k++)
      printf(" ");
 
    for (j = i; j <= rows; j++)
      printf("* ");
 
    printf("\n");
  }
 
  return 0;
}



C Code for Printing a Hollow Hourglass Shape

Explain Program

Step :1

Variable Declarations:

int i, j, k, rows;

  • i, j, k: Loop control variables
  • rows: Number of rows (input from the user)

Step :2

 Input from the user:

printf("Enter the no. of rows: ");

scanf("%d", &rows);

  • The user is ask to input the total number of row.

  • example, if rows = 4, the pattern 
  • 4 rows in the upper part
  • 3 rows in the lower part

Step :3

heading:


printf("Output: \n\n");

 heading for clarity.

Step :4

 Upper Part of the Pattern:

for (i = 1; i <= rows; i++)

{

    for (k = 1; k < i; k++)

        printf(" ");

     for (j = i; j <= rows; j++)

        printf("* ");

    printf("\n");

}

loop prints an inverted right-aligned triangle of stars.


  • i goes from 1 to rows — each iteration is a new row.
  • k prints spaces before the stars. The number of spaces increases each row to push the stars to the right.

        j prints * from the current row number to rows. So, stars decrease in each row

Step :5

Lower Part of the Pattern:

for (i = rows - 1; i >= 1; i--)

{    for (k = 1; k < i; k++)

        printf(" ");

     for (j = i; j <= rows; j++)

        printf("* ");

     printf("\n");

}

 loop prints a right-aligned triangle of stars

This loop prints a right-aligned triangle of stars (opposite of the first).

  • Starts from rows - 1 and goes down to 1.
  • In each row:
  • Prints spaces first (decreasing).
  • Then prints stars (increasing count).


C Program to print Hollow Hourglass pattern 

Output :-


C Program to print Hollow Hourglass pattern


C Program to print Hollow Hourglass pattern 

Summary 

  • The upper triangle shrinks (top-down).
  • The lower triangle grows (bottom-up).
  • Both are right-aligned because of the space handling (printf(" ")).
  • Nested loops (loop inside loop)
  • Controlling spaces and stars to format patterns
  • Symmetry in output (first half decreasing, second half increasing)
  • User input and loops for dynamic patterns

Related Post :- 

C program to print full pyramid of star

C program to print inverted half