P123 第36题 年月日

#include
void printdate(int year,int month,int day)
{
 int B;
 if((year%4==0&&year%100!=0)||year%400==0)
        B=29;
    else
        B=28;
 switch(month)
 {
  case 1:if(day<=31)
      printf("January %d,%d\n",day,year);
      else
       printf("错误\n");
      break;
  case 2:if(day<=B)
      printf("February %d,%d\n",day,year);
      else
       printf("错误\n");
      break;
  case 3:if(day<=31)
      printf("March %d,%d\n",day,year);
      else
       printf("错误\n");
      break;
  case 4:if(day<=30)
      printf("April %d,%d\n",day,year);
      else
       printf("错误\n");
      break;
  case 5:if(day<=31)
      printf("May %d,%d\n",day,year);
      else
       printf("错误\n");
      break;
  case 6:if(day<=30)
      printf("June %d,%d\n",day,year);
      else
       printf("错误\n");
      break;
  case 7:if(day<=31)
      printf("July %d,%d\n",day,year);
      else
       printf("错误\n");
      break;
  case 8:if(day<=30)
      printf("August %d,%d\n",day,year);
      else
       printf("错误\n");
      break;
  case 9:if(day<=31)
      printf("September %d,%d\n",day,year);
      else
       printf("错误\n");
      break;
  case 10:if(day<=30)
      printf("October %d,%d\n",day,year);
      else
       printf("错误\n");
      break;
  case 11:if(day<=31)
      printf("Nevember %d,%d\n",day,year);
      else
       printf("错误\n");
      break;
  case 12:if(day<=30)
      printf("December %d,%d\n",day,year);
      else
       printf("错误\n");
      break;
  default:if(day<=31)printf("错误\n");
 }
}
int main()
{
 int y,m,d;
 while(1)
 {
  scanf("%d%d%d",&y,&m,&d);
  printdate(y,m,d);
 }
 return 0;
}

P123 第36题 年月日_第1张图片

你可能感兴趣的:(第三章,函数,数组与指针)