C Program
C program to Print Alphabet D 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
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;
No comments:
Post a Comment