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-10  ส่วนของโปรแกรมหาว่าเดือนกุมภาพันธ์มี 28 หรือ 29 วันจากเลขปี ค.ศ.
int d2 = 28;
if ((y%400) == 0) {
  d2 = 29;
}
if ((y%4) == 0) {   
  if ((y%100) != 0) {
    d2 = 29;
  }
}

int d2 = 28; if ((y%400) == 0) { d2 = 29; } if ( ((y%4) == 0) && ((y%100) != 0) ) { d2 = 29; }
int d2 = 28; if ( ((y%400)==0) || (((y%4)==0) && ((y%100)!=0))) { d2 = 29; // สังเกตเงื่อนไขบน ใส่วงเล็บให้ทำ && ก่อน || }
int d2; if ( ((y%400)==0) || (((y%4)==0) && ((y%100)!=0))) { d2 = 29; } else { d2 = 28; }
©2009 S.Prasitjutrakul