万年历系统编程
发布网友
发布时间:2024-10-10 11:44
我来回答
共2个回答
热心网友
时间:2024-10-18 09:35
可以运行,但显示格式有问题,一会吃过饭再查原因
#include <stdio.h>
#include <time.h>
int main(void)
{
int year,month,day;
int days=0,i,j,n,m,k,o;
int m1[]={31,28,31,30,31,30,31,31,30,31,30,31};
int m2[]={31,29,31,30,31,30,31,31,30,31,30,31};
time_t today;
struct tm *p;
time(&today);
p=localtime(&today);
year=p->tm_year+1900;
month=p->tm_mon+1;
day=p->tm_mday;
printf(" %4d-%02d\n",year,month);
//if(year>=0)
for(i=0;i<year;i++)
{
if((i%4==0&&i%100!=0)||i%400==0)
days=days+366;
else
days=days+365;
}
if((year%4==0&&year%100!=0)||year%400==0)
for(j=0;j<month-1;j++)
{
days=days+m2[j];
m=m2[month];
}
else //if去掉
for(j=0;j<month-1;j++)
{
days=days+m1[j];
m=m1[month];
}
days=days+day-2;
n=days%7;
//无效,删除else
//无效,删除printf("日期错误\n");
if(day>1)
k=(7-(day-n+6)%7)%7;
else if(day==1)
k=n;
printf("sun mon tue wen thu fri sat\n");
for(o=0;o<k;o++)
printf(" ");
for(o=k;o<k+m;o++)
{
printf("%4d",o-k+1);
if(o%7==6)
printf("\n");
}
return 0;
}
热心网友
时间:2024-10-18 09:35
else printf("日期错误\n");
分号改成英文的试试
追问应该不是这个问题,改成了分号之后出现的还是相同的问题