Posted by : Unknown
Wednesday, February 3, 2016
*****
* *
* *
* *
*****
Ans:
#include <stdio.h>
int main()
{
int i, j, n;
//Reads number of rows from user
printf("Enter value of n : ");
scanf("%d", &n);
//Iterates over each row one by one
for(i=1; i<=n; i++)
{
//Iterates over each column of the i-th row
for(j=1; j<=n; j++)
{
if(i!=1 && i!=n && j!=1 && j!=n)
{
printf(" ");
}
else
{
//Print star for first and last row and for first and last column
printf("*");
}
}
//Move to the next line/row
printf("\n");
}
return 0;
}
**********OUTPUT**********
Enter value of n : 5
*****
* *
* *
* *
*****
*************************
Related Posts :
- Back to Home »
- Star Patterns »
- 34.Hollow square or rectangular star pattern using *'s as shown below.