on
CSS
- Get link
- X
- Other Apps

#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:
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.
Inner Loop:
for (b = 0; b < n; b++)
This controls the columns within 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 *.
If any of the three conditions is true, print a *. Otherwise, print a space
( ).
printf("*");
printf(" ");
printf("\n");
After each row is completed move courser next line to start the next
Comments
Post a Comment