fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void)
  5.  
  6. {
  7. int rows;
  8. int i, j;
  9. int n = 0;
  10.  
  11. printf ("How many rows do you want? ");
  12. if (scanf("%d", & rows) != 1 || rows < 1) return EXIT_FAILURE;
  13. printf ("\n");
  14.  
  15. for (i = 1; i <= rows; ++ i) {
  16. for (j = 0; j < i; ++ j) {
  17. printf ("%4d", n + (i % 2 == 0 ? i - j : j + 1));
  18. }
  19. printf ("\n");
  20. n = n + i;
  21. }
  22.  
  23. return EXIT_SUCCESS;
  24. }
Success #stdin #stdout 0s 9424KB
stdin
20
stdout
How many rows do you want? 
   1
   3   2
   4   5   6
  10   9   8   7
  11  12  13  14  15
  21  20  19  18  17  16
  22  23  24  25  26  27  28
  36  35  34  33  32  31  30  29
  37  38  39  40  41  42  43  44  45
  55  54  53  52  51  50  49  48  47  46
  56  57  58  59  60  61  62  63  64  65  66
  78  77  76  75  74  73  72  71  70  69  68  67
  79  80  81  82  83  84  85  86  87  88  89  90  91
 105 104 103 102 101 100  99  98  97  96  95  94  93  92
 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121
 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
 171 170 169 168 167 166 165 164 163 162 161 160 159 158 157 156 155 154
 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191