ログイン
kid's world

今月は何日まである?

#include <stdio.h>

main()
{
  int year, month, day;
  
  printf("年:");
  scanf("%d",&year);
  scanf("%d",&month);
  
  switch(month){
  case 1:
  case 3:
  case 5:
  case 7:
  case 8:
  case 10:
  case 12:
    day=31;
    break;
  case 4:
  case 6:
  case 9:
  case 11:
    day=30;
    break;
  case 2:
    day=28;
    break;
  default:
    day=0;
  }
  
  if(day==0)
  else
}
if(year % 4 ==0)
  day=29;
else
  day=28;
year % 4 ==0 && year % 100 != 0
year % 4 ==0 && year % 100 !=0 || year % 400 == 0
  case 2:
    if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
      day=29;
    else
      day=28;
    break;

/c/condition-fig4.png


広告


©Toshio Koide 1996-2007.

mail.gif

広告