Originally Posted by
Adak
I only see 7 rows high with the height of 8.
Yes, thanks for the remark, here is the corrected version. Now that I look to the picture he provided, as I understand, only height = 0 is ignored but not height = 1. Also for each height H and line number N, there is H - N spaces before the current line.
Code:
#include <stdio.h>
int main()
{
int height = -1;
int line = 0;
int counter = 0;
while (height < 0 || height > 23)
{
printf("Enter the height: ");
scanf("%d", &height);
}
printf("\n");
for(line = 1; line <= height; line++)
{
int spaceNum = height - line;
int spaceCounter = 1;
for (spaceCounter = 0; spaceCounter < spaceNum ; spaceCounter++)
printf(" ");
for(counter = 0; counter <= line ; counter++)
printf("#");
printf("\n");
}
return 0;
}
Which gives the following result
Code:
$ gcc -Wall testscript.c -o testscript
$ ./testscript
Enter the height: 0
$ ./testscript
Enter the height: 1
##
$ ./testscript
Enter the height: 2
##
###
$ ./testscript
Enter the height: 3
##
###
####
$ ./testscript
Enter the height: 4
##
###
####
#####
$ ./testscript
Enter the height: 8
##
###
####
#####
######
#######
########
#########
$
Regards,
Dariyoosh