Skip to content

Instantly share code, notes, and snippets.

@ruhi1999
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save ruhi1999/922d85309821fd45fbca to your computer and use it in GitHub Desktop.

Select an option

Save ruhi1999/922d85309821fd45fbca to your computer and use it in GitHub Desktop.
right-aligns hashtag pyramid given height; does not accept over 23
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int n,i,j,k;
do
{
printf("Height:");
n=GetInt();
}
while (n>23 || n<0);
int hashes=2;
int spaces=n-1;
for (i=0; i < n; i++)
{
for (j=0; j<spaces; j++)
{
printf(" ");
}
for (k=0; k<hashes; k++)
{
printf("#");
}
hashes++;
spaces--;
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment