Need help with C homework problem
Hello,
My name is ali and I am currently enrolled in edx.org program for computer science. On my problem set I was assign to create the pillars in mario:
jharvard@appliance (~/Dropbox/pset1): ./mario
Height: 8
##
###
####
#####
######
#######
########
#########
****The pillars are aligned to the left and not right but for some reason it won't let me post it that way.****
I have to first prompt the user for the half-pyramid's height, a non-negative integer no greater than 23. (The height of the half-pyramid pictured above happens to be 8.) If the user fails to provide a non-negative integer no greater than 23, you should re-prompt for the same again. Then, generate (with the help of printf and one or more loops) the desired half-pyramid. Also I have take care to align the bottom-left corner of your half-pyramid with the left-hand edge of your terminal window.
So far this is what I got from my solution. But the problem is They don't align properly and I don't understand how to use the \n in a loop to make that happen:
Code:
#include <stdio.h>
int main(void)
{
int h, s, i;
do
{
printf("Height: ");
scanf("%d", &h);
}
while(h <= 0 || h > 23);
for(s = 0; s < h - 1; s++)
{
printf(" ");
}
for(i = 0;i < h ; i++)
{
printf("#");
}
return 0;
}
I can only use "do" "while" and "for" to solve this problem. I would really appreciate it if someone could guide me here