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