Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3.  
  4. void PrintPyramid(int height);
  5. void print_space (int num);
  6. void print_hash (int num);
  7.  
  8. int main(void)
  9. {
  10.     int i = 0;
  11.     do
  12.     {
  13.         printf("Input integer must be positive and less then 24: ");
  14.         i  = GetInt();    
  15.     }
  16.     while(i > 23 || i < 0);
  17.        
  18.     PrintPyramid(i);
  19. }
  20.  
  21. void PrintPyramid(int height)
  22. {
  23.     for (int i = 1; i <= height; i++)
  24.     {
  25.         print_space(height - i);
  26.         print_hash(i);
  27.        
  28.         print_space(height/2);
  29.        
  30.         print_hash(i);
  31.         printf("\n");
  32.     }
  33. }
  34.  
  35. void print_space (int num)
  36. {
  37.     for (int i = 0; i < num; i++)
  38.     {
  39.         printf(" ");
  40.     }
  41. }
  42.  
  43. void print_hash (int num)
  44. {
  45.     for (int i = 0; i < num; i++)
  46.     {
  47.         printf("#");
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement