fork(1) download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. char ToAscii(int val)
  5. {
  6. return (val >= 0 && val <= 'Z' - 'A')? val + 'A': ' ';
  7. }
  8.  
  9. int main(void)
  10. {
  11. int n;
  12. int i, j;
  13. printf("Please indicate the number of stairs.\n>");
  14. scanf("%d", &n);
  15.  
  16. printf("\n");
  17. printf("i = [%d, %d]\n", 1 - n, n - 1);
  18. printf("j = [%d, %d]\n", 1 - n, n - 1);
  19.  
  20. printf("\n");
  21. printf("f(i, j) = i + j\n");
  22.  
  23. for(i = 1 - n; i < n; ++i)
  24. {
  25. for(j = 1 - n; j < n; ++j)
  26. {
  27. int val = i + j;
  28. printf("%c", ToAscii(val));
  29. }
  30. printf("\n");
  31. }
  32.  
  33. printf("\n");
  34. printf("f(i, j) = abs(i) + abs(j)\n");
  35.  
  36. for(i = 1 - n; i < n; ++i)
  37. {
  38. for(j = 1 - n; j < n; ++j)
  39. {
  40. int val = abs(i) + abs(j);
  41. printf("%c", ToAscii(val));
  42. }
  43. printf("\n");
  44. }
  45.  
  46. printf("\n");
  47. printf("f(i, j) = %d - (abs(i) + abs(j))\n", n - 1);
  48.  
  49. for(i = 1 - n; i < n; ++i)
  50. {
  51. for(j = 1 - n; j < n; ++j)
  52. {
  53. int val = n - 1 - abs(i) - abs(j);
  54. printf("%c", ToAscii(val));
  55. }
  56. printf("\n");
  57. }
  58. return 0;
  59. }
Success #stdin #stdout 0.02s 1680KB
stdin
3
stdout
Please indicate the number of stairs.
>
i = [-2, 2]
j = [-2, 2]

f(i, j) = i + j
    A
   AB
  ABC
 ABCD
ABCDE

f(i, j) = abs(i) + abs(j)
EDCDE
DCBCD
CBABC
DCBCD
EDCDE

f(i, j) = 2 - (abs(i) + abs(j))
  A  
 ABA 
ABCBA
 ABA 
  A