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. if (p < 10) {
  12. putchar('0' + p);
  13. } else if (p < 36) {
  14. putchar('A' + p - 10);
  15. } else {
  16. putchar('a' + p - 36);
  17. }
  18. }
  19.  
  20. void btree(int n) {
  21. int a = (1 << n) - 1;
  22. int b = ((a + 1) >> 1) - 1;
  23. int c = 1;
  24. int p = 1;
  25. int i, j;
  26.  
  27. for (i = 0; i < n; i++) {
  28. string(' ', b);
  29. for (j = 0; j < c; j++) {
  30. if (j > 0) {
  31. string(' ', a);
  32. }
  33. printItem(p);
  34. p++;
  35. }
  36. c <<= 1;
  37. a = b;
  38. b = ((a + 1) >> 1) - 1;
  39. putchar('\n');
  40. }
  41. }
  42.  
  43.  
  44. int main(void) {
  45. int i;
  46.  
  47. for (i = 1; i <= 6; i++) {
  48. btree(i);
  49. string('-', 64);
  50. putchar('\n');
  51. }
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 2008KB
stdin
Standard input is empty
stdout
1
----------------------------------------------------------------
 1
2 3
----------------------------------------------------------------
   1
 2   3
4 5 6 7
----------------------------------------------------------------
       1
   2       3
 4   5   6   7
8 9 A B C D E F
----------------------------------------------------------------
               1
       2               3
   4       5       6       7
 8   9   A   B   C   D   E   F
G H I J K L M N O P Q R S T U V
----------------------------------------------------------------
                               1
               2                               3
       4               5               6               7
   8       9       A       B       C       D       E       F
 G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V
W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z { |
----------------------------------------------------------------