C program
C program to Print Alphabet I star pattern
Example
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;
No comments:
Post a Comment