Write a program to print a square of size 5 by using the character S as shown below:
(a) S S S S S (b) S S S S S
S S S S S S S
S S S S S S S
S S S S S S S
S S S S S S S S S S
#include <stdio.h>
void main()
{
int row,column;
clrscr();
for(row=1;row<=5;row++)
{
for(column=1;column<=5;column++)
printf("S");
putchar('\n');
}
printf("\n\n");
for(row=1;row<=5;row++)
{
for(column=1;column<=5;column++)
{
if(row>1&&row<5&&column>1&&column<5)
printf(" ");
else
printf("S");
}
putchar('\n');
}
getch();
}
(a) S S S S S (b) S S S S S
S S S S S S S
S S S S S S S
S S S S S S S
S S S S S S S S S S
#include <stdio.h>
void main()
{
int row,column;
clrscr();
for(row=1;row<=5;row++)
{
for(column=1;column<=5;column++)
printf("S");
putchar('\n');
}
printf("\n\n");
for(row=1;row<=5;row++)
{
for(column=1;column<=5;column++)
{
if(row>1&&row<5&&column>1&&column<5)
printf(" ");
else
printf("S");
}
putchar('\n');
}
getch();
}
No comments:
Post a Comment