C Program to Print Alphabet C Star Pattern with Example

C Program

C Program to Print Alphabet C Star Pattern with Example


 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;

}


C Program to Print Alphabet C Star Pattern with Example
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

Comments

Popular posts from this blog

HTML Tag

HTML Input Type Submit Syntax and Example

CSS Text Color Explained with Syntax and HTML Examples