C Program
Example
C Program to Print Hollow Square Star Pattern
Explain Program
Step :1
#include <stdio.h>
Standards Input Output library, printf and scanf.
Step :2
int main()
entry point of the program.
i for iterating through rows,
Step :3
printf("Enter number of rows: ");
scanf("%d", &N);
user to input a number (N), which defines the
dimension of the square.
square will have N rows and N columns.
Step :4
Outer Loop:
Rows
for(i=1; i<=N; i++)
loop run from 1 to N (inclusive) to handlerow.
Step :5
Inner Loop:
Columns
for(j=1; j<=N; j++)
loop runs for each column within a row (again from 1 to
N).
Step :6
Logic to Print the Border
if(i==1 || i==N || j==1 || j==N)
condition check current cell border
of the square:
First column: j == 1
condition is true:
Step :7
printf("*");
Print an asterisk (*).
Step :8
printf(" ");
Print a space ( ) to create the hollow center.
Step :9
printf("\n");
After finishing row, move to the next line.
Step :10
program finished successfully
No comments:
Post a Comment