/*
Toward the end of World 1-1 in Nintendo's Super Mario Brothers, Mario must ascend a "half-pyramid" of blocks before leaping toward a flag pole. Here is a representation that instead of blocks it uses hashes (#) and its maximum height is 23.
*/
#include <stdio.h>
#include <cs50.h>
int main (void)
{
int height;//height of the half-pyramid
do
{
printf("Height: ");
scanf("%d", &height);//gets height from the user
}while(height<0 || height>23);//if height is less than 0 or more than 23 ask again
for(int i=1; i<=height;i++)//
{
//every space must be the heigth - #ofStep
int spaces = height - i;
for(int j=0; j<spaces; j++)
{
printf(" ");
}
//every row of blocks must be #ofStep + 1
for(int blocks=0; blocks<i+1; blocks++)
{
printf("#");
}
printf("\n");//next line
}
return 0;
}
December 6, 2012
Pirámide en C
Bueno aquí les comparto un programa que realicé en un curso, consiste en dibujar la mitad de una pirámide utilizando el símbolo gato (#) esto muy parecido a la pirámide que se ve en el primer mundo del video juego de Mario Bro's de Nintendo. El programa pide al usuario la altura de la pirámide que debe ser mayor a 0 y menor o igual a 23 y en base a esto dibuja la pirámide
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment