Description
This program prints the pattern shown below. The number of 's' at each side is read as input from the user, then the program uses a nested for loop to print the pattern.
ssssssss
s s
s s
s s
sssssss
Program
// square pattern c program.
//program for pattern printing using for loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int n; /*pattern s */
clrscr();
printf("Enter the value for n");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i>0 && i<(n-1))
if(j==0 | j==(n-1))
printf("s");
else
printf(" ");
else
printf("s");
}
printf("\n");
}
getch();
}
Output
| C program to print pattern |
No comments:
Post a Comment