一个关于计算那天是星期几的c程序

如题所述

#include<stdio.h>
int second(int year, int month, int days)
{
static int mdays[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 };
int i, y = year - 1;
for (i=0; i<month; ++i) days += mdays[i];
if (month>2)
{
if (((year%400)==0) || ((year&3)==0 && (year%100))) ++days;
}
return (y+y/4-y/100+y/400+days)%7;
}

void secondproblem()
{
int year,month,day,w;
static char* wday[]={ "日","一","二","三","四","五","六" };
printf("请输入年份:\n");
scanf("%d",&year);
printf("请输入月份:\n");
scanf("%d",&month );
printf("请输入日期:\n");
scanf("%d",&day);
w = second(year,month,day);
printf("%d年%d月%d日 是星期%s.\n\n", year, month, day, wday[w]);

}

int main()
{
secondproblem();
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-06-12
vcbbbcvbvcb
相似回答
大家正在搜