c语言万年历代码
输入年月日,输出距今天还有多少天,星期几,是否是公历节日
输入年月日,输出距今天还有多少天,星期几,是否是公历节日
答案:这个程序有一个功能是查询输入的一天是这一年的第几天
/* welcome to use the WanNianLi system!
孙辉
*/
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
char* month_str[]={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
char* week[]={"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31}; //初始化每个月的天数
int leap (int year)//判断闰年
{
if(year%4==0&&year%100!=0||year%400==0)
return 1;
else return 0;
}
int month_day(int year,int month) //判断这一个月有多少天
{
if(leap(year)&&month==2 )
return 29;
else
return(mon_day[month-1]);}
int firstday(int year,int month,int day)//判断这一个月的第一天是星期几
{
int c=0;
float s;
int m;
for(m=1;m<month;m++)
c=c+month_day(year,m);
c=c+day;
s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;
return ((int)s%7);
}
int printone(int a,int b) //打印出一个月的日历
{
printf(" --------------------------------------------------------------------------\n");
printf(" 日 一 二 三 四 五 六\n ");
int i,j=1,k=1;
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");
return 1;
}
int PrintAllYear(int year)/*打印出一年的日历*/
{
int a,b;
int j=1,n=1,k;
printf("\n\n **************%d年的挂历**************\n",year);
for(k=1;k<=12;k++)
{
j=1,n=1;
b=month_day(year,k);
a=firstday(year,k,1);
printf("\n\n %s\n",month_str[k-1],k);
printone(a,b);
}
return 1;
}
char *shux(int year) //计算是什么生肖的函数
{
static char *sx[]={"子鼠","丑牛","寅虎","卯兔" , "辰龙","巳蛇", "午马",
"未羊", "申猴","酉鸡","戌狗","戌狗", "亥猪"
};
return(sx[(year-1204)%12]);
}
int tianshu(int year,int month,int day) //计算某天是该年的第几天
{
int i,sum=0;
for(i=1;i<month;i++)
sum=sum+mon_day[i-1];
sum=sum+day;
if((year%4==0&&year%100!=0 ||year%400==0)&&month>2)
sum=sum+1;
printf( "\n输入的%d年%d月%d日是这一年的第%d天\n 你是否还要继续查询?(Y/N)?",year,month,day,sum);
return 1;}
//****************************************************
int main()
{
int option,da;
char ch;
int year,month,day;
printf("\n **************************************************\n * Copyright @ 2005 孙辉 All rights reserved!");
printf(" *\n * *\n * 欢迎使用万年历系统,祝您心情愉快! *\n **************************************************\n");
//调用系统时间
time_t tval;
struct tm *now;
tval = time(NULL);
now = localtime(&tval);
printf("\n qq:214467962\n\n 现在时间: %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 a,b;
b=month_day(now->tm_year+1900,now->tm_mon+1);
a=firstday (now->tm_year+1900,now->tm_mon+1,now->tm_mday);
printone(a,b); //打印出本月的日历
//******************************************************************
while(1)
{
printf("\n请选择你所需要的服务:\n");
printf("\n输入1:求某个日期对应是星期几");
printf("\n输入2:判断某年是否为闰年");
printf("\n输入3:输出某年的日历");
printf("\n输入4:判断你是什么属相");