### Thread: Mario's Pyramid

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2012
Posts
5
Rep Power
0

#### Mario's Pyramid

I have been trying to use c to create a half pyramid that is aligned to the right, like the one in mario, except like this.

##
###
####
#####
######
#######
########
#########

Except my code does not produce that can you guys help me with my code see, if theres anything wrong. I have 2 different versions.

1.
#include <stdio.h>
int main (void)
{
int height;
printf("please enter a positive integer no more than 23:")
scanf("%i", &height);

while(height > 23|height <=0)
{
printf("please enter a positive integer no more than 23:")
scanf("%i", &height);
}
for ( int y= 9- height; y<height;y++)
{
printf(" ");
}
for ( int x= 9- height; x<height;x++)
{
printf("#");
}
printf("\n");
return 0;
}

2. The other is

#include <stdio.h>
int main (void)
{
int height;
printf("please enter a positive integer no more than 23:")
scanf("%i", &height);

while(height > 23|height <=0)
{
printf("please enter a positive integer no more than 23:")
scanf("%i", &height);
}
for ( int y= 9- height; y<height;y++)
{
printf(" ");
printf("#");
printf("\n");
height= (height-1);
}
return 0;
}

so which code do you think is better? And how could i fix the problems and flaws.
2. Compilers are quite accurate. If your compiler tells you you need a semi-colon between printf and scanf statement, insert one.

Or is a good concept. You need logical or || instead of the bitwise or which has different precedence.
Code:
```(height > 23|height <=0)  /* wrong */

((height < 1) || (23 < height)) /* correct */```
Happy holiday!
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2012
Posts
5
Rep Power
0
Thanks, i managed to complete it!