万年历(C语言编程)

发布网友 发布时间:2022-04-24 17:05

我来回答

2个回答

热心网友 时间:2023-10-24 16:24

#include<stdio.h>
#include<time.h>
int leap (int year)//判断闰年
{
if(year%4==0&&year%100!=0||year%400==0)
return 1;
else return 0;
}
int days_month (int month,int year)//判断月
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
return 31;
if(month==4||month==6||month==9||month==11)
return 30;
if(month==2&&leap(year)==1) return 29;
else return 28;
}
int firstday(int month,int year)//判断年
{
int w;
w=(1+2*month+3*(month+1)/5+year+year/4+year/400-year/100)%7+1;
return w;
}
main()
{
//调用系统时间
time_t tval;
struct tm *now;
tval = time(NULL);
now = localtime(&tval);
printf("现在时间: %4d年 %d月 %02d日 %d:%02d:%02d\n", now->tm_year+1900, now->tm_mon+1, now->tm_mday,
now->tm_hour, now->tm_min, now->tm_sec);
//调用结束

int i,j=1,k=1,a,b,month,year;
b=days_month(now->tm_mon+1,now->tm_year+1900);
a=firstday (now->tm_mon+1,now->tm_year+1900);
printf(" Sun Mon Tue Wed Thu Fri Sat \n");
if(a==7)
{
for(i=1;i<=b;i++)
{
printf("%4d",i);
if(i%7==0)
{
printf("\n");
}
}
}
if(a!=7)
{
while (j<=4*a)
{
printf(" ");
j++;
}
for(i=1;i<=b;i++)
{
printf("%4d",i);
if(i==7*k-a)
{
printf("\n");
k++;
}
}
}
printf("\n");
}

热心网友 时间:2023-10-24 16:24

#include<stdio.h>
#include<time.h>
int
leap
(int
year)//判断闰年
{
if(year%4==0&&year%100!=0||year%400==0)
return
1;
else
return
0;
}
int
days_month
(int
month,int
year)//判断月
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
return
31;
if(month==4||month==6||month==9||month==11)
return
30;
if(month==2&&leap(year)==1)
return
29;
else
return
28;
}
int
firstday(int
month,int
year)//判断年
{
int
w;
w=(1+2*month+3*(month+1)/5+year+year/4+year/400-year/100)%7+1;
return
w;
}
main()
{
//调用系统时间
time_t
tval;
struct
tm
*now;
tval
=
time(NULL);
now
=
localtime(&tval);
printf("现在时间:
%4d年
%d月
%02d日
%d:%02d:%02d\n",
now->tm_year+1900,
now->tm_mon+1,
now->tm_mday,
now->tm_hour,
now->tm_min,
now->tm_sec);
//调用结束
int
i,j=1,k=1,a,b,month,year;
b=days_month(now->tm_mon+1,now->tm_year+1900);
a=firstday
(now->tm_mon+1,now->tm_year+1900);
printf("
Sun
Mon
Tue
Wed
Thu
Fri
Sat
\n");
if(a==7)
{
for(i=1;i<=b;i++)
{
printf("%4d",i);
if(i%7==0)
{
printf("\n");
}
}
}
if(a!=7)
{
while
(j<=4*a)
{
printf("
");
j++;
}
for(i=1;i<=b;i++)
{
printf("%4d",i);
if(i==7*k-a)
{
printf("\n");
k++;
}
}
}
printf("\n");
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com