c program to display alphabet pattern N with asterisk
C program to Print Alphabet N star pattern
C program to Print Alphabet N star pattern
Example
Explain Program
Step :1
#include <stdio.h>
This includes the Standard Input Output library. It is necessary to use
functions like printf() for output.
int main()
This is the main function from where the execution of the program
int a, b;
These are loop variables:
- a: for controlling rows
- b: for controlling columns
int n = 7;
defines the height (and width) of the pattern. The 'N' pattern will be print in a 7x7 grid. You can change n to any positive integer to scale the size of the 'N'
Outer Loop:
for (a = 0; a < n; a++)
This controls the rows of the pattern.
- a = 0 to a = 6 ( n = 7)
- For each value of a, one full line (row) of output is printed
Inner Loop:
for (b = 0; b < n; b++)
This controls the columns within each row.
- b = 0 to b = 6 for each row
Conditional:
if (b == 0 || b == n - 1 || b == a)
This is the heart of the logic. It decides where to print an asterisk *.
- b == 0: First column → left vertical line of the 'N'
- b == n - 1: Last column → right vertical line of the 'N'
- b == a: Diagonal top-left to bottom-right (row index == column index)
If any of the three conditions is true, print a *. Otherwise, print a space
( ).
printf("*");
printf(" ");
- Print a * when the condition is met (position of vertical or diagonal part of 'N')
- Print a space otherwise
printf("\n");
After each row is completed move courser next line to start the next
Output

Post a Comment