fork(1) download
  1. /* author: Leonardone @ NEETSDKASU */
  2. #include <stdio.h>
  3.  
  4. void string(char c, int n) {
  5. while (n-- > 0) {
  6. putchar(c);
  7. }
  8. }
  9.  
  10. void printItem(int p) {
  11. printf("%02d", p);
  12. }
  13.  
  14. void btree2(int n) {
  15. int a = (1 << n) - 1;
  16. int b = ((a + 1) >> 1) - 1;
  17. int c = 1;
  18. int p = 1;
  19. int i, j;
  20.  
  21. for (i = 0; i < n; i++) {
  22. string(' ', b << 1);
  23. for (j = 0; j < c; j++) {
  24. if (j > 0) {
  25. string(' ', a << 1);
  26. }
  27. printItem(p);
  28. p++;
  29. }
  30. c <<= 1;
  31. a = b;
  32. b = ((a + 1) >> 1) - 1;
  33. putchar('\n');
  34. }
  35. }
  36.  
  37.  
  38. int main(void) {
  39. int i;
  40.  
  41. for (i = 1; i <= 6; i++) {
  42. btree2(i);
  43. string('-', 64);
  44. putchar('\n');
  45. }
  46.  
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 2052KB
stdin
Standard input is empty
stdout
01
----------------------------------------------------------------
  01
02  03
----------------------------------------------------------------
      01
  02      03
04  05  06  07
----------------------------------------------------------------
              01
      02              03
  04      05      06      07
08  09  10  11  12  13  14  15
----------------------------------------------------------------
                              01
              02                              03
      04              05              06              07
  08      09      10      11      12      13      14      15
16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31
----------------------------------------------------------------
                                                              01
                              02                                                              03
              04                              05                              06                              07
      08              09              10              11              12              13              14              15
  16      17      18      19      20      21      22      23      24      25      26      27      28      29      30      31
32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63
----------------------------------------------------------------