C语言问题(高手请进)

2024-12-19 21:08:19
推荐回答(3个)
回答1:

用C有菜单?
大概这样吧
int n;
do{
scanf("%d",&n);
}while(n>9999||n<0)

回答2:

#include
char* month_str[]={"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
char* week[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
int IsLeapYear(int year) //判断是否是闰年的函数定义
{
if((year%4==0&&year%100!=0)||(year%400==0))
return 1;
else
return 0;
}
int month_day(int year,int month) //判断月份天数函数定义
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(IsLeapYear(year)&&month==2)
return 29;
else
return(mon_day[month-1]);
}
int DaySearch(int year,int month,int day) /*查询星期函数定义*/
{
int c=0;
float s;
int m;
for(m=1;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 PrintYearMonth(int year,int month) //输出月份日历函数定义
{
int temp;
int i=month,j;
printf("\n\n %d年%s\n\n",year,month_str[i-1]);
printf(" 星期日 星期一 星期二 星期三 星期四 星期五 星期六 \n\n");
temp=DaySearch(year,i,1);
for(j=1;j<=month_day(year,i)+temp;j++)
{
if(j-temp<=0)
printf(" ");
else if(j-temp<10)
printf(" %d ",j-temp);
else
printf(" %d ",j-temp);
if(j%7==0)
printf("\n");
}
return 0;
}
int PrintYear(int year)/*输出年份日历函数定义*/
{
int temp;
int i,j;
printf("\n\n 公元%d 年日历\n\n",year);
printf("\n\n***************************************************************************\n");
for(i=1;i<=12;i++)
{
printf("\n\n %s\n\n",month_str[i-1]);
printf(" 星期日 星期一 星期二 星期三 星期四 星期五 星期六 \n\n");
temp=DaySearch(year,i,1);
for(j=1;j<=month_day(year,i)+temp;j++)
{
if(j-temp<=0)
printf(" ");
else if(j-temp<10)
printf(" %d ",j-temp);
else
printf(" %d ",j-temp);
if(j%7==0)
printf("\n");
}
printf("\n\n***************************************************************************\n");
}
return 0;
}
int NumbleDay(int year,int month,int day) //天数查询函数定义
{
int i,nday=day;
if(month==1)
nday=day;
else for(i=1;i nday=nday+month_day(year,i);
return nday;
}
int NumWeek(int year,int month,int day) //星期序数查询函数定义
{
int nweek=0,shu=day,a;
a=-DaySearch(year,month,1);
do
{
shu=shu-7;
nweek=nweek+1;
}
while(shu>a);
return nweek;
}
int WhichDay(int month,int day,int theweek)
{
int year;
for(year=2009;;year--)
{
if(theweek==DaySearch(year,month,day))
{
return year;
break;
}
}
}
void main()
{
int year,month,day,shuzi,numday,numble,nuweek,theyear,theweek;
char c;
printf("\n\n 万年历查询");
while(1)
{
printf("\n\n***************************************************************************\n");
printf(" 1. 月份查询(任意输入一个月份,显示该月份的日历)请输入数字“1”\n\n");
printf(" 2. 年份日历查询(任意输入一个年份,显示该年份的日历)请输入数字“2”\n\n");
printf(" 3. 天数查询(输入任意一天,查出该天是该年第几天)请输入数字“3”\n\n");
printf(" 4. 星期查询(输入任意一天,查出该天是该月第几周星期几)请输入数字“4”\n\n");
printf(" 5. 农历查询(输入任意一天,查出该天对应的农历是哪一天)请输入数字“5”\n\n");
printf(" 6. 年份查询(输入月份、日期和星期查出该天属于哪一年(今年向前最近的那年))\n\n 请输入数字“6”\n\n");
printf("\n 开始查询!请选择查询项目\n");
scanf("%d",&shuzi);
switch(shuzi)
{
case 1:
{
printf("\n你选择的是月份查询。\n");
printf("\n请输入你要查询年份(xxxx)的月份(xx):\n");
scanf("%d",&year);
scanf("%d",&month);
printf("你输入的是公元%d年%d月。\n",year,month);
PrintYearMonth(year,month) ;
}

break;
case 2:
{
printf("\n你选择的是年份日历查询。\n");
printf("\n请输入你要查询的年份(xxxx):\n");
scanf("%d",&year);
printf("你输入的年份是公元%d年。\n",year);
PrintYear(year);

}
break;
case 3:
{
printf("\n你选择的是天数排序查询。\n");
printf("\n请输入你要查询的日期:\n");
printf("请分别输入xxxx年、xx月、xx日:\n");
scanf("%d",&year);
scanf("%d",&month);
scanf("%d",&day);
printf("你输入的日期是:公元%d年%d月%d日\n",year,month,day);
numday=NumbleDay(year,month,day);
printf("该天为该年的第%d天。\n",numday);
}
break;
case 4:
{
printf("\n你选择的是星期查询。\n");
printf("\n请输入你要查询的日期:\n");
printf("请分别输xxxx年、xx月、xx日:\n");
scanf("%d",&year);
scanf("%d",&month);
scanf("%d",&day);
printf("你输入的日期是:公元%d年%d月%d日\n",year,month,day);
numble=DaySearch(year,month,day);
nuweek=NumWeek(year,month,day);
printf("这是公元%d年%d月第%d周%s。\n",year,month,nuweek,week[numble]);
}
break;
case 5:
{
printf("\n你选择的是农历查询。\n");
printf("\n请输入你要查询的日期:\n");
printf("请分别输入xxxx年、xx月、xx日:\n");
scanf("%d",&year);
scanf("%d",&month);
scanf("%d",&day);
printf("你输入的日期是:公元%d年%d月%d日\n",year,month,day);
}
break;
case 6:
{
printf("\n你选择的是年份查询。\n");
printf("\n请分别输入你知道的月份(xx)、(xx)日和星期(星期日输入0,星期一输入1,~ ~星期六输入6):\n");
scanf("%d",&month);
scanf("%d",&day);
scanf("%d",&theweek);
theyear=WhichDay(month,day,theweek);
printf("这天出现距今最近的一年是公元%d年。",theyear);
}
break;
default:
printf("\n 对不起,没有此项查询!请重新输入!\n\n");
break;
}
}
}

回答3:

这个简单,有谁可以制作农历的万年历,我给1000分!

小斌