fork download
  1. void o3(int *a, int *b, int *c) {
  2. int tmp;
  3. switch ((*a>*b) + 2*(*b>*c) + 4*(*a>*c)) { // <== hidden ifs
  4. default: break; // case 3 and case 4 never happen
  5. case 0: /*already in order*/ break; // no swapping
  6. case 1: tmp = *a; *a = *b; *b = tmp; break; // swap a and b
  7. case 2: tmp = *b; *b = *c; *c = tmp; break; // swap b and c
  8. case 7: tmp = *a; *a = *c; *c = tmp; break; // swap a and c
  9. case 5: tmp = *a; *a = *b; *b = *c; *c = tmp; break; // swap a and b and c
  10. case 6: tmp = *a; *a = *c; *c = *b; *b = tmp; break; // swap a and c and b
  11. }
  12. }
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <time.h>
  17.  
  18. int main(void) {
  19. srand(time(0));
  20. for (int k = 0; k < 256; k++) {
  21. int a = rand() % 10, b = rand() % 10, c = rand() % 10;
  22. o3(&a, &b, &c);
  23. printf("%d%d%d ", a, b, c);
  24. }
  25. puts("");
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
069 679 124 579 889 133 368 258 149 145 139 299 356 014 489 389 399 499 459 022 245 355 079 023 057 038 457 134 389 034 567 012 026 449 234 667 015 568 889 399 134 026 138 035 489 455 179 456 245 369 012 456 467 238 238 688 158 356 038 035 167 557 449 048 014 239 018 138 047 113 237 467 026 236 277 278 038 018 002 015 356 117 245 334 069 569 069 139 239 236 389 256 007 233 138 467 356 117 059 013 136 457 579 469 579 357 009 347 044 455 469 049 367 679 069 347 056 022 468 138 224 288 199 177 049 046 166 249 247 056 011 249 128 045 179 477 033 444 038 158 223 348 245 268 356 277 459 239 236 279 026 347 016 556 247 335 227 249 579 148 579 146 777 345 004 357 059 144 999 023 278 889 567 023 368 038 468 128 357 459 489 346 134 245 368 256 167 134 116 025 789 339 577 019 478 016 015 368 679 378 679 599 068 059 579 135 125 156 134 279 016 137 468 599 667 388 116 469 128 368 247 558 346 368 257 236 379 058 139 479 779 244 227 889 345 015 177 123 235 289 008 467 168 478 489 445 347 077 022 236 145 058 136 122 012 567