4. เลือกปฏิบัติ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 4-20  ส่วนของโปรแกรมหาค่ามัธยฐานของ a, b, และ c
int median;
if (a < b) {
  if (b < c)
     median = b;   // a < b < c
  else
     if (a < c)  
       median = c; // a < c <= b
     else
       median = a; // c <= a < b
} else {
  if (a < c)
     median = a;   // b <= a < c
  else
     if (b < c)  
       median = c; // b < c <= a
     else
       median = b; // c <= b <= a
}
©2009 S.Prasitjutrakul