Displaying an inverted pyramid of asterisks
Posted
by onyebuoke
on Stack Overflow
See other posts from Stack Overflow
or by onyebuoke
Published on 2010-03-31T19:23:48Z
Indexed on
2010/03/31
19:33 UTC
Read the original article
Hit count: 504
I help in my for my program. I am required 2 create a inverted pyramid of stars which rows depends on the number of stars the user keys, but I've done it so it does not give an inverted pyramid, it gives a regular pyramid.
#include <stdio.h>
#include <conio.h>
void printchars(int no_star, char space);
int getNo_of_rows(void);
int main(void)
{
int numrows, rownum;
rownum=0;
numrows=getNo_of_rows();
for(rownum=0;rownum<=numrows;rownum++)
{
printchars(numrows-rownum, ' ');
printchars((2*rownum-1), '*');
printf("\n");
}
_getche();
return 0;
}
void printchars(int no_star, char space)
{
int cnt;
for(cnt=0;cnt<no_star;cnt++)
{
printf("%c",space);
}
}
int getNo_of_rows(void)
{
int no_star;
printf("\n Please enter the number of stars you want to print\n");
scanf("%d",&no_star);
while(no_star<1)
{
printf("\n number incorrect, please enter correct number");
scanf("%d",&no_star);
}
return no_star;
}
© Stack Overflow or respective owner