HOLLOW INVERTED PYRAMID STAR
Consider the following I/O samples.
SAMPLE INPUT: 3
SAMPLE OUTPUT: * * * * *
* *
*
C PROGRAM:
#include <stdio.h>
int main()
{
int row,col,spc,n;
scanf("%d",&n);
for(row=n; row>=1; --row)
{
for(spc=n; spc>row; spc--)
{
printf(" ");
}
for(col=1; col<2*row; col++)
{
if(row==n || col==1 || col==2*row-1)
printf("* ");
else
printf(" ");
}
printf("\n");
}
return 0;
}
int main()
{
int row,col,spc,n;
scanf("%d",&n);
for(row=n; row>=1; --row)
{
for(spc=n; spc>row; spc--)
{
printf(" ");
}
for(col=1; col<2*row; col++)
{
if(row==n || col==1 || col==2*row-1)
printf("* ");
else
printf(" ");
}
printf("\n");
}
return 0;
}
OUTPUT:
The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.
If you have any feedback about this article and want to improve this, please comment in the comment section.
Comments
Post a Comment