C program to generate a square in C language
#include<stdio.h>
main()
{
int i,j,n;
printf("\t enter size of square to generate a square : ");
scanf("%d",&n);
for(i=1;i<=n;i++) // for row
{
for(j=1;j<=n;j++) // for column
{
if(i==1||i==n) // to fill the first and last line..
printf("S "); //print s in first and last line ..
else{ // condition for remianing lines..
if(j==1||j==n) // condition for first and last column
printf("S ",j); // prints the s in first and last column ..
else
printf(" "); // leave space for remaining rows ..
}
}
printf("\n"); // print new line after every row...
}
}
Watch video :https://youtu.be/hKxYeZ5To9Q
Comments
Post a Comment