
December 21st, 2012, 07:13 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 5
Time spent in forums: 1 h 19 m 53 sec
Reputation 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.
|