fork download
  1. #include <stdio.h>
  2. void swap(int *x, int *y) {
  3. int tmp = *y;
  4. *y = *x;
  5. *x = tmp;
  6. }
  7. int main() {
  8. int a = 3, b = 1, c = 2;
  9. if (a > b) {
  10. swap(&a, &b);
  11. }
  12. if (b > c) {
  13. swap(&b, &c);
  14. }
  15. if (a > b) {
  16. swap(&a, &b);
  17. }
  18. printf("a=%d, b=%d, c=%d\n", a, b, c);
  19. return 0;
  20. }
Success #stdin #stdout 0s 5236KB
stdin
stdout
a=1, b=2, c=3