#include<stdio.h>
#include<stdlib.h>
# define Y 2011
# define M 7
# define D 1
void date(int year,int month,int day) /*日期查询程序*/
{
int n,s=0,i,j,week,t
int b[12]={0,31,59,90,120,151,181,212,243,273,304,334}
if(year%4==0&&year%100!=0||year%400==0)
for (i=0i<12i++)
b[i]++
if(year>Y)
{
n=year-Y
s=s+(day-1)/*日期互补*/
for(i=0i<=(n-1)i++)
{
j=2011+i
if(j%4==0&&j%100!=0||j%400==0) /*判断是否是闰年 */
s+=366
else s+=365}
}
else
{
n=Y-year
s=s-(day-1)
t=year
for(i=0i<=n-1i++)
{
if((t=t+i)%4==0&&t%100!=0||t%400==0)
s+=366
else s+=365
}
}
if(month<7) /*月份互补*/
s=s+(181-b[month-1])
else
s=s+(b[month-1]-181)
printf ("\n\n")
week=((year-1)+(year-1)/4-(year-1)/100+(year-1)/400+(b[month-1]+day))%7/*蔡勒公式*/
printf ("\n")
printf ("%d-%d-%d 是:",year,month,day)
switch (week) /*判断是星期几*/
{
case 0:{printf ("星期天")break}
case 1:{printf ("星期一")break}
case 2:{printf ("星期二")break}
case 3:{printf ("星期三")break}
case 4:{printf ("星期四")break}
case 5:{printf ("星期五")break}
case 6:{printf ("星期六")break}
}
printf ("\n\n%d-%d-%d",year,month,day)
printf("距今天有%d天\n",s)
}
void nongli(int year)
{
int a,b
a=(year-3)%10
b=(year-3)%12
printf("%d是",year)
switch(a)
{
case 1:printf("甲")break
case 2:printf("已")break
case 3:printf("丙")break
case 4:printf("丁")break
case 5:printf("戊")break
case 6:printf("己")break
case 7:printf("庚")break
case 8:printf("辛")break
case 9:printf("壬")break
case 10:printf("癸")break
}
switch(b)
{
case 5:printf("辰")break
case 6:printf("巳")break
case 7:printf("午")break
case 8:printf("未")break
case 9:printf("申")break
case 10:printf("酉")break
case 11:printf("戌")break
case 0:printf("亥")break
case 1:printf("子")break
case 2:printf("丑")break
case 3:printf("寅")break
case 4:printf("卯")break
}
printf("年\n\n")
}
void jieqi()
{ }
int main()
{
int option
char ch
int year,month,day
printf("Copyright @ 2005 TianQian All rights reserved!:):):)")
printf("\n\n Welcome to use the WanNianLi system!\n")
while(1)
{
printf(" ……………………………………………………………\n")
printf(" **\n")
printf(" 欢迎使用万年历查询系统 \n")
printf(" **\n")
printf(" ……………………………………………………………\n")
printf("\n 1 日期查询")
printf("\n 2 公农历查询")
printf("\n 3 节气查询")
printf("\n 4 Exit\n")
scanf("%d",&option)
switch(option)
{
case 1:
while(1)
{
printf("\nPlease input the year,month and day(XXXX,XX,XX):")
scanf("%d,%d,%d,%c",&year,&month,&day)
date(year,month,day)
printf("\ndo you want to continue?(Y/N)")
fflush(stdin)
scanf("%c",&ch)
if(ch=='N'||ch=='n')
break
}
break
case 2:
while(1)
{
printf("\nPlease input the year which needs searched?(XXXX)")
scanf("%d",&year)
nongli(year)
fflush(stdin)
printf("\ndo you want to continue?(Y/N)")
scanf("%c",&ch)
if(ch=='N'||ch=='n')
break
}
break
case 3:
while(1)
{
jieqi()
printf("** 抱歉,该功能尚未实现! **")
printf("\nDo you want to continue to print(Y/N)?")
fflush(stdin)
scanf("%c",&ch)
if(ch=='N'||ch=='n')
break
}
break
case 4:
fflush(stdin)
printf("Are you sure?(Y/N)")
scanf("%c",&ch)
if(ch=='Y'||ch=='y')
exit(0)
break
default:
printf("\nError:Sorry,there is no this service now!\n")
break
}
}
return 0
}
标准C语言版本,在任何系统下都可以运行
#!/bin/bashwhile [ true ]
do
read -p "请输入年份和月份,用空格分割,比如 2015 1,输入end结束 :" year mon
if [ "$year" == "end" ]then exitfi
cal $mon $year
done
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)