fork download
  1. #include <stdio.h>
  2.  
  3. T(n)
  4. {
  5. int i=0, j, x=1,d=0;
  6. while(x<=n) x+=x,++d; // count the digits
  7. // each binary digit is approximately 0.3 decimal digit
  8. // this approximation is accurate enough for the task
  9. for(;i<=n;i++)
  10. for(j=0;j<=n;j++)
  11. printf("%*d%c",
  12. d*3/10+1,
  13. i^j,
  14. j < n ? 32:10); // space between columns, newline at end
  15. }
  16.  
  17. int main(void) {
  18. // your code goes here
  19. int n=9;
  20. scanf("%d", &n);
  21. T(n);
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 2116KB
stdin
Standard input is empty
stdout
 0  1  2  3  4  5  6  7  8  9
 1  0  3  2  5  4  7  6  9  8
 2  3  0  1  6  7  4  5 10 11
 3  2  1  0  7  6  5  4 11 10
 4  5  6  7  0  1  2  3 12 13
 5  4  7  6  1  0  3  2 13 12
 6  7  4  5  2  3  0  1 14 15
 7  6  5  4  3  2  1  0 15 14
 8  9 10 11 12 13 14 15  0  1
 9  8 11 10 13 12 15 14  1  0