Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void stars_row (int x, int n)
- {
- int c = n / 2, l = c - x / 2, r = c + x / 2;
- for (int i = 0; i < n; i++)
- {
- if (l <= i && i <= r) printf ("*");
- else printf (" ");
- }
- printf ("\n");
- }
- void print_tree (int s[], int sz) {
- int mx = 0;
- for (int i = 0; i < sz; i++) {
- if (mx < s[i]) {
- mx = s[i];
- }
- }
- for (int i = 0; i < sz; i++) {
- stars_row (2 * s[i] + 1, 2 * mx + 1);
- }
- }
- int main ()
- {
- int a[] = {1, 2, 3, 2, 1, 4, 5, 2};
- print_tree (a, 8);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement