Eng-Mohamed-Essam

Untitled

Jul 12th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. void loop(void);
  4. int main(void)
  5. {   int s = 7;
  6.     int H, i, L;
  7.     printf("please Enter an integer value :"); //Taking the hight from the user
  8.     scanf("%d", &H);
  9.     if (H > 0 && H <= 8)
  10.     {
  11.         for (i = 1; i <= H; i++) // loops for buliding the pyramid
  12.         {
  13.             for (L = 1; L <= i; L++)
  14.             {    s--;
  15.                 do
  16.                 {
  17.                     printf(".");
  18.                     s--;
  19.                 }
  20.                 while(s!=0);
  21.                 printf("#");
  22.             }
  23.             printf("\n");
  24.    
  25.         }
  26.     }
  27.  
  28.     else if (H <= 0 || H > 8)  //if the value isn't right
  29.     {
  30.         do// very important to repeat the error msg in case the user keeps putting a wrong number .
  31.         {
  32.             printf("Error please Enter a correct Value: ");
  33.             scanf("%d", &H);
  34.         }
  35.         while (H <= 0 || H > 8);// the condition to repeat the error msg
  36.         if (H > 0 && H <= 8)
  37.         {
  38.             for (i = 1; i <= H; i++) // the loop for building the pyramid again .
  39.             {    
  40.                 for (L = 1; L <= i; L++)
  41.                 {  
  42.                     printf("#");
  43.                 }
  44.                 printf("\n");
  45.             }
  46.         }
  47.     }
  48.     return 0 ;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment