Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void stars_row (int x, int n)
  4. {
  5.     int c = n / 2, l = c - x / 2, r = c + x / 2;
  6.     for (int i = 0; i < n; i++)
  7.     {
  8.         if (l <= i && i <= r) printf ("*");
  9.         else printf (" ");
  10.     }
  11.     printf ("\n");
  12. }
  13.  
  14. void print_tree (int s[], int sz) {
  15.     int mx = 0;
  16.    
  17.     for (int i = 0; i < sz; i++) {
  18.         if (mx < s[i]) {
  19.             mx = s[i];
  20.         }
  21.     }
  22.        
  23.     for (int i = 0; i < sz; i++) {
  24.         stars_row (2 * s[i] + 1, 2 * mx + 1);
  25.     }
  26.        
  27. }
  28.  
  29. int main ()
  30. {
  31.     int a[] = {1, 2, 3, 2, 1, 4, 5, 2};
  32.    
  33.     print_tree (a, 8);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement