输入日期求星期的程序

发布时间:2017-1-17 8:44:50 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"输入日期求星期的程序",主要涉及到输入日期求星期的程序方面的内容,对于输入日期求星期的程序感兴趣的同学可以参考一下。

/***  week.c*  version:1.0 2006-9-14 *  auther:jsp**  W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7 *  在公式中d表示日期中的日数,m表示月份数,y表示年数。 *  注意:在公式中有个与其他公式不同的地方: *   把一月和二月看成是上一年的十三月和十四月,例:如果是2004-1-10则换算成:2003-13-10来代入公式计算。*/#include"stdio.h" struct data{ short year; short month; short day;}; int IsLoopYear(struct data *today){ if((today->year % 400 == 0)||((today->year % 100 != 0) &&(today->year % 4 == 0)))  return 1; else return 0;} void main(){ struct data today,ctoday; short week;  while(1) {  printf("请输入今天的日期(dddd-dd-dd):");  scanf("%d-%d-%d",&today.year ,&today.month ,&today.day);  if(today.month ==2)   if (IsLoopYear(&today) == 1)    if((today.day > 29) || (today.day < 1))    {     printf("日期输入错误请重来!/n");     continue;    }      if(today.month ==2)   if (IsLoopYear(&today) == 0)    if((today.day > 28) ||(today.day < 1))    {     printf("日期输入错误请重来!/n");     continue;    }   if((today.month == 1) || (today.month == 3) ||(today.month == 5)||(today.month == 7)||(today.month == 8)||(today.month == 10)||(today.month == 12))   if((today.day > 31) ||(today.day < 1))   {    printf("日期输入错误请重来!/n");    continue;   }  if((today.month == 4) || (today.month == 6) ||(today.month == 9)||(today.month == 11))   if((today.day > 30) ||(today.day < 1))   {    printf("日期输入错误请重来!/n");    continue;   }    if((today.month >12) || (today.month < 1))  {   printf("月份输入错误请重来!/n");   continue;   }   ctoday = today; if(today.month == 1 ) {  today.month = 13;  today.year = today.year-1; }  if(today.month == 2 ) {  today.month = 14;  today.year = today.year-1; }  week = (today.day + 2*today.month +3*(today.month  + 1)/5+today.year +today.year /4-today.year /100+today.year /400) %7; week ++;  switch(week) { case 1:  printf("%d年%d月%d日是星期一/n",ctoday.year ,ctoday.month ,ctoday.day );  break; case 2:  printf("%d年%d月%d日是星期二/n",ctoday.year ,ctoday.month ,ctoday.day );  break; case 3:  printf("%d年%d月%d日是星期三/n",ctoday.year ,ctoday.month ,ctoday.day );  break; case 4:  printf("%d年%d月%d日是星期四/n",ctoday.year ,ctoday.month ,ctoday.day );  break; case 5:  printf("%d年%d月%d日是星期五/n",ctoday.year ,ctoday.month ,ctoday.day );  break; case 6:  printf("%d年%d月%d日是星期六/n",ctoday.year ,ctoday.month ,ctoday.day );  break; case 7:  printf("%d年%d月%d日是星期天/n",ctoday.year ,ctoday.month ,ctoday.day );  break; } }} 

上一篇:刚来CSDN Blog的感受
下一篇:黑客江湖之东邪西毒南帝北丐中神通

相关文章

相关评论