C Program
C program to Print Alphabet C star pattern
Example
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 == rows - 1 → Bottom row (last row)
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.
No comments:
Post a Comment