fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int median(int left, int mid, int right){
  5. int mediana;
  6.  
  7. if(mid < right && mid < left) mediana = (left < right) ? left : right;
  8. else{
  9. if(mid > right){
  10. if(mid < left){
  11. mediana = mid;
  12. }else mediana = (left < right) ? left : right;
  13. }else if(mid > left){
  14. mediana = mid;
  15. }else mediana = left;
  16. }
  17.  
  18. return mediana;
  19. }
  20.  
  21. int main(void) {
  22. int left = 3;
  23. int mid = 2;
  24. int right = 1;
  25. int mediana;
  26.  
  27. if(left > mid){
  28. if(left < right){
  29. mediana = left;
  30. }else mediana = mid;
  31. }else if(mid > right){
  32. mediana = right;
  33. }else mediana = right;
  34.  
  35. printf("%d\n", mediana);
  36.  
  37. int i;
  38. for(i = 0; i < 20; i++){
  39. left = rand() % 4;
  40. mid = rand() % 4;
  41. right = rand() % 4;
  42. printf("l = %d, m = %d, r = %d, mediana = %d\n", left, mid, right, median(left, mid, right));
  43. }
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
2
l = 3, m = 2, r = 1, mediana = 2
l = 3, m = 1, r = 3, mediana = 3
l = 2, m = 0, r = 1, mediana = 1
l = 1, m = 2, r = 3, mediana = 2
l = 2, m = 3, r = 3, mediana = 3
l = 2, m = 0, r = 2, mediana = 2
l = 0, m = 0, r = 3, mediana = 0
l = 0, m = 3, r = 1, mediana = 0
l = 2, m = 2, r = 2, mediana = 2
l = 3, m = 3, r = 3, mediana = 3
l = 1, m = 2, r = 2, mediana = 2
l = 2, m = 1, r = 3, mediana = 2
l = 1, m = 0, r = 3, mediana = 1
l = 2, m = 1, r = 1, mediana = 2
l = 1, m = 3, r = 0, mediana = 0
l = 1, m = 2, r = 0, mediana = 0
l = 3, m = 2, r = 1, mediana = 2
l = 2, m = 3, r = 0, mediana = 0
l = 0, m = 1, r = 2, mediana = 1
l = 2, m = 0, r = 1, mediana = 1