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("%03d", p);
  12. }
  13.  
  14. void btree3(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 * 3);
  23. for (j = 0; j < c; j++) {
  24. if (j > 0) {
  25. string(' ', a * 3);
  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. btree3(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
001
----------------------------------------------------------------
   001
002   003
----------------------------------------------------------------
         001
   002         003
004   005   006   007
----------------------------------------------------------------
                     001
         002                     003
   004         005         006         007
008   009   010   011   012   013   014   015
----------------------------------------------------------------
                                             001
                     002                                             003
         004                     005                     006                     007
   008         009         010         011         012         013         014         015
016   017   018   019   020   021   022   023   024   025   026   027   028   029   030   031
----------------------------------------------------------------
                                                                                             001
                                             002                                                                                             003
                     004                                             005                                             006                                             007
         008                     009                     010                     011                     012                     013                     014                     015
   016         017         018         019         020         021         022         023         024         025         026         027         028         029         030         031
032   033   034   035   036   037   038   039   040   041   042   043   044   045   046   047   048   049   050   051   052   053   054   055   056   057   058   059   060   061   062   063
----------------------------------------------------------------