求某年月日是星期几

    xiaoxiao2025-01-19  13

    /*求某年/月/日是星期几*/ #include<stdio.h> //星期函数声明 int weekday(int year,int month,int day); void main() { int year,month,day,flag; int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; printf("请输入年份:\n"); scanf("%d",&year); printf("请输入月份:\n"); scanf("%d",&month); printf("请输入日号:\n"); scanf("%d",&day); days[1] = (year%4==0 && year0!=0 || year@0==0) ? 29:28;//闰年调整 if(year>0 && month>0 && month<13 && day>0 && day<=days[month-1])//判断输入是否正确 { flag=weekday(year,month,day); switch(flag) { case 0: printf("%d年%d月%d日是星期日\n",year,month,day); break; case 1: printf("%d年%d月%d日是星期一\n",year,month,day); break; case 2: printf("%d年%d月%d日是星期二\n",year,month,day); break; case 3: printf("%d年%d月%d日是星期三\n",year,month,day); break; case 4: printf("%d年%d月%d日是星期四\n",year,month,day); break; case 5: printf("%d年%d月%d日是星期五\n",year,month,day); break; case 6: printf("%d年%d月%d日是星期六\n",year,month,day); break; default: printf("输入错误,请重新输入!\n",year,month,day); } }else { printf("输入错误,请重新输入!\n"); } } int weekday(int year,int month,int day) { int Weekday=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7; return Weekday; }

    运行结果:

    最新回复(0)