Write a Program that reads in the side of a square and then prints that square out of asterisks.Your program should work for squares of all sides sizes between 1-20.For example it should look like this :
*****
* *
* *
* *
*****
Code :
#include <stdio.h>
int main(void)
{
int i = 1,sides,j = 1,m = 1,b = 1,n;
printf("Enter number of sides of square to be printed :");
scanf("%d",&sides);
while ( m <= sides)
{
printf("*");
m++;
}
while ( b < sides - 1)
{
printf("\n*");
n = 2;
while ( n < sides )
{
printf(" ");
n++ ;
}
if ( n == sides)
printf("*");
b++;
}
printf("\n") ;
while ( i <= sides)
{
printf("*");
i++;
}
return 0;
}
*****
* *
* *
* *
*****
Code :
#include <stdio.h>
int main(void)
{
int i = 1,sides,j = 1,m = 1,b = 1,n;
printf("Enter number of sides of square to be printed :");
scanf("%d",&sides);
while ( m <= sides)
{
printf("*");
m++;
}
while ( b < sides - 1)
{
printf("\n*");
n = 2;
while ( n < sides )
{
printf(" ");
n++ ;
}
if ( n == sides)
printf("*");
b++;
}
printf("\n") ;
while ( i <= sides)
{
printf("*");
i++;
}
return 0;
}
No comments:
Post a Comment