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