来自  资质荣誉 2019-09-22 14:52 的文章
当前位置: 澳门太阳娱乐手机登录 > 资质荣誉 > 正文

判断闰年,调用万年历

图片 1

include<stdio.h>

void leapYear(int year)
{
if((year%4==0 && year%100!=0) || year%400==0)
{
printf("%d是闰年n",year);
}
else
{
printf("%d不是闰年n",year);
}
}
void Oftheweek(int year,int month)
{
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int i;
int sum=0;
if(year<1900||month<1||month>12)
{
printf("input error");
}
else
{
for(i=1900;i<year;i++)
{
if((i%4==0 && i%100!=0) || i%400==0)
{
sum+=366;
}
else
{
sum+=365;
}
}
// printf("sum=%dn",sum);
if((year%4==0 && year%100!=0) || year%400==0)
{
a[2]=29;
}
else
{
a[2]=28;
}
for(i=1;i<month;i++)
{
sum+=a[i];
}
}
int week=sum%7;
week=(week+1)%7;
printf("%d年%d月的第一天是星期%dn",year,month,week);
}
void calendar(int year,int month)
{
int i;
int sum=0;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(year<1900||month<1||month>12)
{
printf("input error");
}
else
{
for(i=1900;i<year;i++)
{
if((i%4==0 && i%100!=0) || i%400==0)
{
sum+=366;
}
else
{
sum+=365;
}
}
// printf("sum=%dn",sum);
if((year%4==0 && year%100!=0) || year%400==0)
{
a[2]=29;
}
else
{
a[2]=28;
}
for(i=1;i<month;i++)
{
sum+=a[i];
}
}
int week=sum%7;
week=(week+1)%7;
// printf("week=%dn",week);
printf("ttt%d/%dn",year,month);
printf("SuntMontTuestWedtThurtFritSatn");
int colum=0;
i=1;
for(colum=0;i<=week;colum++)
{
printf("t");
i++;
}
for(i=1;i<=a[month];i++)
{
printf("%2dt",i);
colum++;
if(colum%7==0)
{
printf("n");
}
}
printf("n");
}
int main()
{
int year;
printf("请输入想要查询的年份判断是否为闰年:");
scanf("%d",&year);
leapYear(year);
printf("请输入查询的年份和月份判断当月的第一天是星期几:");
int year1,month1;
scanf("%d%d",&year1,&month1);
Oftheweek(year1,month1);
printf("请输入查询的年份和月份查看日历:");
int year2,month2;
scanf("%d%d",&year2,&month2);
calendar(year2,month2);
return 0;
}

c语言代码实现如下:

#include <stdio.h>
int main() {
int year;
scanf("%d", &year);
if((year % 100 !=0 && year % 4 == 0) || year % 400 ==0){
printf;
}else{
printf;
}
return 0;
}

本文由澳门太阳娱乐手机登录发布于 资质荣誉,转载请注明出处:判断闰年,调用万年历

关键词: