6

Half pyramid

view full story
linux-howto

http://www.daniweb.com – I just hit a brick wall. I'm writing a code that will ask a user the height of a pyramid an output the corresponding pyramid with * characters. I got that part working but now I need to turn it into a half pyramid like so: * ** *** **** ***** assuming its a height of 5. So far I have been unable to solve this problem, any pointers or suggestions? This is my code so far: #include <stdio.h> int main() {         int row, column, user_input;         int x = 0;         printf("Enter a height\n");         scanf("%d", &user_input);         for(row = 1; row <= user_input; row++)         {                 for (column = 1; column <= user_input * 2 - 1; column++)                 if (column <= user_input + x && column >= user_input - x)                         printf("*");                 else                         printf(" ");                         printf("\n");                         x++;         }if (user_input < 1)                         printf("Height must be at least one\n"); } Thanks in advance. (General)