Advertisement
liftchampion

sasa

Oct 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.73 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int ft_sum_arithm_seq(int a, int d, int n)
  4. {
  5.     int a_n;
  6.    
  7.     a_n = a + d * (n - 1);
  8.     return ((n * (a + a_n)) / 2);
  9. }
  10.  
  11. void sastantua(int l)
  12. {
  13.     int i;
  14.     int j;
  15.     int space_count;
  16.    
  17.     i = 1;
  18.     while(i <= l)
  19.     {
  20.         j = 1;
  21.         space_count = 0;
  22.         //printf("(%d %d)\n", (3 + (l - 1) * 2) / 2, 3 + (i - 1) * 2);
  23.         while (j <= space_count + 3 + (i - 1) * 2)
  24.         {
  25.            
  26.             if (j <= (3 + (l - 1) * 2) / 2 - (3 + (i - 1) * 2) / 2)
  27.             {
  28.                 printf(" ");
  29.                 space_count++;
  30.             }
  31.             else if (j == (3 + (l - 1) * 2) / 2 - (3 + (i - 1) * 2) / 2 + 1)
  32.             {
  33.                 printf("/");
  34.             }
  35.             else if (j > (3 + (l - 1) * 2) / 2 - (3 + (i - 1) * 2) / 2 + 1 && j < space_count + 3 + (i - 1) * 2)
  36.             {
  37.                 printf("*");
  38.             }
  39.             else if (j == space_count + 3 + (i - 1) * 2)
  40.             {
  41.                 printf("\\");
  42.             }
  43.             //printf("(%d %d)", j, space_count + 3 + (i - 1) * 2);
  44.             j++;
  45.         }
  46.         printf("\n");
  47.         i++;
  48.     }
  49. }
  50.  
  51. int ft_get_height(int n)
  52. {
  53.     int h;
  54.     int i;
  55.     int j;
  56.     int last_floor_h;
  57.     int ignore;
  58.    
  59.     h = 0;
  60.     i = 1;
  61.     last_floor_h = 2;
  62.     ignore = 1;
  63.     while (i++ <= n)
  64.     {
  65.         j = 1;
  66.         while (j++ <= last_floor_h + 1 + ignore)
  67.             h++;
  68.         if (last_floor_h % 2 == 1)
  69.             ignore++;
  70.         last_floor_h++;
  71.         printf("\n--- %d %d (%d)---", ignore, last_floor_h, h);
  72.     }
  73.     return (h);
  74. }
  75.  
  76. int main()
  77. {
  78.     sastantua(9);
  79.    
  80.    printf("%d", ft_get_height(4));
  81.    
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement