请c语言高手帮我改一下 这个万年历程序 我要答辩 很急 下面又要求和代码!谢谢 10
#include<stdio.h>intmain(){intc,x,num,year,month,day,j=1,k=1;printf("欢迎来到简易万年历\n\n");...
#include <stdio.h>
int main()
{
int c,x,num,year,month,day,j=1,k=1;
printf("欢迎来到简易万年历\n\n");
printf("请输入年:");
scanf("%d",&year);
printf("\n请输入月:");
scanf("%d",&month);
printf("\n请输入日:");
scanf("%d",&day);
printf("\n请输本年1月1号是星期几?:");
scanf("%d",&j);
printf("\n");
if
(((year%4==0)&&(year%100!=0))||(year%400==0)) x=29;
else
x=28;
if
(month==1) c=day;
else if
(month==2) c=31+day;
else if
(month==3) c=31+x+day;
else if
(month==4) c=31+31+x+day;
else if
(month==5) c=31+31+30+x+day;
else if
(month==6) c=31+31+30+31+x+day;
else if
(month==7) c=31+31+30+31+30+x+day;
else if
(month==8) c=31+31+30+31+30+31+x+day;
else if
(month==9) c=31+31+30+31+30+31+31+x+day;
else if
(month==10) c=31+31+30+31+30+31+31+30+x+day;
else if
(month==11) c=31+31+30+31+30+31+31+30+31+x+day;
else if
(month==12) c=31+31+30+31+30+31+31+30+31+30+x+day;
num=(c-1)%7+j;
if(x==28)
printf("今年不是闰年!\n今天是今年的第%d周!\n今天是%d年%d月%d日 星期%d 是%d年的第%d天\n",c/7+1,year,month,day,num,year,c);
else
printf("今年是闰年!\n");
printf("今天是今年的第%d周!\n",c/7+1);
printf("今天是%d年%d月%d日 星期%d\n" ,year,month,day,num);
printf("今天是%d年的第%d天\n",year,c);
return 0;
}
,输入2013 1 1时 程序就自己消失了,而且我想把那个要求 输入本年的一月一日是星期几改成我输入日期之后可以自动输出的 还有代码行数要求超过一百行(可以加一些 很小的东西,总之 时程序更易操作 更人性化就行 ) 希望 高手帮我 改进一下 难度要低。。。。我没有学到指针 很急 谢谢 成功后追加悬赏 展开
int main()
{
int c,x,num,year,month,day,j=1,k=1;
printf("欢迎来到简易万年历\n\n");
printf("请输入年:");
scanf("%d",&year);
printf("\n请输入月:");
scanf("%d",&month);
printf("\n请输入日:");
scanf("%d",&day);
printf("\n请输本年1月1号是星期几?:");
scanf("%d",&j);
printf("\n");
if
(((year%4==0)&&(year%100!=0))||(year%400==0)) x=29;
else
x=28;
if
(month==1) c=day;
else if
(month==2) c=31+day;
else if
(month==3) c=31+x+day;
else if
(month==4) c=31+31+x+day;
else if
(month==5) c=31+31+30+x+day;
else if
(month==6) c=31+31+30+31+x+day;
else if
(month==7) c=31+31+30+31+30+x+day;
else if
(month==8) c=31+31+30+31+30+31+x+day;
else if
(month==9) c=31+31+30+31+30+31+31+x+day;
else if
(month==10) c=31+31+30+31+30+31+31+30+x+day;
else if
(month==11) c=31+31+30+31+30+31+31+30+31+x+day;
else if
(month==12) c=31+31+30+31+30+31+31+30+31+30+x+day;
num=(c-1)%7+j;
if(x==28)
printf("今年不是闰年!\n今天是今年的第%d周!\n今天是%d年%d月%d日 星期%d 是%d年的第%d天\n",c/7+1,year,month,day,num,year,c);
else
printf("今年是闰年!\n");
printf("今天是今年的第%d周!\n",c/7+1);
printf("今天是%d年%d月%d日 星期%d\n" ,year,month,day,num);
printf("今天是%d年的第%d天\n",year,c);
return 0;
}
,输入2013 1 1时 程序就自己消失了,而且我想把那个要求 输入本年的一月一日是星期几改成我输入日期之后可以自动输出的 还有代码行数要求超过一百行(可以加一些 很小的东西,总之 时程序更易操作 更人性化就行 ) 希望 高手帮我 改进一下 难度要低。。。。我没有学到指针 很急 谢谢 成功后追加悬赏 展开
4个回答
展开全部
#include<stdio.h>
#include<windows.h>
int menu()
{
char ch;
int x;
system("cls");
printf("请选择相应的菜单:\n");
printf("***********************************\n");
printf("查询某年某月某日是星期几,输入1回车:\n");
printf("查询某年是否是闰年,输入2回车:\n");
printf("打印某年的全年日历,输入3回车:\n");
printf("退出,输入0回车:\n");
printf("***********************************\n");
scanf("%d",&x);
if(x==0)
{
printf("确认退出? Y/N ");
ch=getchar();
scanf("%c",&ch);
if(ch=='Y')
exit(0);
else
main();
}
return x;
}
int judge_week(year,mon,day)
{
int sum,i,flag=0;
if(year%400==0)
flag=1;
else if(year%4==0 && year%100!=0)
flag=1;
sum=30*(mon-1)+day;
for(i=1;i<=mon-1;i++)
{
if(i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12)
sum+=1;
if(i==2)
{
if(flag==1)
sum-=1;
if(flag==0)
sum-=2;
}
}
return sum;
}
look_week()
{
int year,mon,day,C,S,k;
char ch,week[7][3]={"日","一","二","三","四","五","六"};
system("cls");
printf("请输入要查询的年月日\nyear month day\n");
scanf("%d %d %d",&year,&mon,&day);
if(year<0 || mon<0 || mon>12 || day<0 || day>31)
{
system("cls");
printf("输入的年月日不正确,请重新输入!");
Sleep(3000);
look_week();
}
C=judge_week(year,mon,day);
S=year-1+(year-1)/4+(year-1)/100+(year-1)/400+C+2;
if(year<=2000 && year>=1901)
S=S+2;
else if(year<=1900)
S+=4;
k=S%7;
system("cls");
printf("\n%d年%d月%d日是星期%s.\n\n",year,mon,day,week[k]);
printf("是否要继续查询? Y/N ");
getchar();
ch=getchar();
if(ch=='Y')
look_week();
else
main();
}
look_runnian()
{
int flag=0,year;
char ch;
system("cls");
printf("请输入要查询的年份: ");
scanf("%d",&year);
if(year%400==0)
flag=1;
else if(year%4==0 && year%100!=0)
flag=1;
system("cls");
if(flag==1)
printf("%d是润年\n",year);
else
printf("%d不是润年\n",year);
printf("是否要继续查询? Y/N ");
getchar();
ch=getchar();
if(ch=='Y')
look_runnian();
else
main();
}
print_calendar()
{
int i,j=0,k,C,S,flag=0,m,year,mon,d[31];
char ch,week[7][3]={"日","一","二","三","四","五","六"};
system("cls");
printf("请输入要打印日历的年、月:\nyear month\n");
scanf("%d %d",&year,&mon);
C=judge_week(year,mon,1);
S=year-1+(year-1)/4+(year-1)/100+(year-1)/400+C+2;
if(year<=2000 && year>=1901)
S=S+2;
else if(year<=1900)
S+=4;
k=S%7;
if(year%400==0)
flag=1;
else if(year%4==0 && year%100!=0)
flag=1;
if(mon==1 || mon==3 || mon==5 || mon==7 || mon==8 || mon==10 || mon==12)
m=31;
else if(mon==2)
{
if(flag==1)
m=29;
if(flag==0)
m=28;
}
else
m=30;
for(i=1;i<=m;i++)
d[j++]=i;
system("cls");
printf("%d年%d月的日历如下:\n\n",year,mon);
for(i=0;i<7;i++)
printf("%s\t",week[i]);
putchar(10);
for(i=0;i<k;i++)
printf("\t");
j=k;
for(i=0;i<m;i++)
{
printf("%d\t",d[i]);
j++;
if(j%7==0)
putchar(10);
}
printf("\n\n是否要继续查询? Y/N ");
getchar();
ch=getchar();
if(ch=='Y')
print_calendar();
else
main();
}
main()
{
int a;
a=menu();
switch(a)
{
case 1:look_week();break;
case 2:look_runnian();break;
case 3:print_calendar();break;
default:
{
printf("输入有误,请重新选择相应的菜单:\n");
Sleep(3000);
main();
}
}
}
//2012年12月20日杨东平写于北京交通大学
//这是我写的,你看下吧
#include<windows.h>
int menu()
{
char ch;
int x;
system("cls");
printf("请选择相应的菜单:\n");
printf("***********************************\n");
printf("查询某年某月某日是星期几,输入1回车:\n");
printf("查询某年是否是闰年,输入2回车:\n");
printf("打印某年的全年日历,输入3回车:\n");
printf("退出,输入0回车:\n");
printf("***********************************\n");
scanf("%d",&x);
if(x==0)
{
printf("确认退出? Y/N ");
ch=getchar();
scanf("%c",&ch);
if(ch=='Y')
exit(0);
else
main();
}
return x;
}
int judge_week(year,mon,day)
{
int sum,i,flag=0;
if(year%400==0)
flag=1;
else if(year%4==0 && year%100!=0)
flag=1;
sum=30*(mon-1)+day;
for(i=1;i<=mon-1;i++)
{
if(i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12)
sum+=1;
if(i==2)
{
if(flag==1)
sum-=1;
if(flag==0)
sum-=2;
}
}
return sum;
}
look_week()
{
int year,mon,day,C,S,k;
char ch,week[7][3]={"日","一","二","三","四","五","六"};
system("cls");
printf("请输入要查询的年月日\nyear month day\n");
scanf("%d %d %d",&year,&mon,&day);
if(year<0 || mon<0 || mon>12 || day<0 || day>31)
{
system("cls");
printf("输入的年月日不正确,请重新输入!");
Sleep(3000);
look_week();
}
C=judge_week(year,mon,day);
S=year-1+(year-1)/4+(year-1)/100+(year-1)/400+C+2;
if(year<=2000 && year>=1901)
S=S+2;
else if(year<=1900)
S+=4;
k=S%7;
system("cls");
printf("\n%d年%d月%d日是星期%s.\n\n",year,mon,day,week[k]);
printf("是否要继续查询? Y/N ");
getchar();
ch=getchar();
if(ch=='Y')
look_week();
else
main();
}
look_runnian()
{
int flag=0,year;
char ch;
system("cls");
printf("请输入要查询的年份: ");
scanf("%d",&year);
if(year%400==0)
flag=1;
else if(year%4==0 && year%100!=0)
flag=1;
system("cls");
if(flag==1)
printf("%d是润年\n",year);
else
printf("%d不是润年\n",year);
printf("是否要继续查询? Y/N ");
getchar();
ch=getchar();
if(ch=='Y')
look_runnian();
else
main();
}
print_calendar()
{
int i,j=0,k,C,S,flag=0,m,year,mon,d[31];
char ch,week[7][3]={"日","一","二","三","四","五","六"};
system("cls");
printf("请输入要打印日历的年、月:\nyear month\n");
scanf("%d %d",&year,&mon);
C=judge_week(year,mon,1);
S=year-1+(year-1)/4+(year-1)/100+(year-1)/400+C+2;
if(year<=2000 && year>=1901)
S=S+2;
else if(year<=1900)
S+=4;
k=S%7;
if(year%400==0)
flag=1;
else if(year%4==0 && year%100!=0)
flag=1;
if(mon==1 || mon==3 || mon==5 || mon==7 || mon==8 || mon==10 || mon==12)
m=31;
else if(mon==2)
{
if(flag==1)
m=29;
if(flag==0)
m=28;
}
else
m=30;
for(i=1;i<=m;i++)
d[j++]=i;
system("cls");
printf("%d年%d月的日历如下:\n\n",year,mon);
for(i=0;i<7;i++)
printf("%s\t",week[i]);
putchar(10);
for(i=0;i<k;i++)
printf("\t");
j=k;
for(i=0;i<m;i++)
{
printf("%d\t",d[i]);
j++;
if(j%7==0)
putchar(10);
}
printf("\n\n是否要继续查询? Y/N ");
getchar();
ch=getchar();
if(ch=='Y')
print_calendar();
else
main();
}
main()
{
int a;
a=menu();
switch(a)
{
case 1:look_week();break;
case 2:look_runnian();break;
case 3:print_calendar();break;
default:
{
printf("输入有误,请重新选择相应的菜单:\n");
Sleep(3000);
main();
}
}
}
//2012年12月20日杨东平写于北京交通大学
//这是我写的,你看下吧
追问
你这个 着实 对于我 来说有难 不过挺有学习价值 等我有时间 好好看看
来自:求助得到的回答
博思aippt
2024-07-20 广告
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
展开全部
你的代码没有大问题。改了改,更好些了,供参考……
#include "stdio.h"//
void main(void){
int c,x,num,year,month,day,j=1,k=1;
printf("欢迎来到简易万年历\n\n");
printf("请输入年:");
scanf("%d",&year);
printf("\n请输入月:");
scanf("%d",&month);
if(month<0 || month>12){
printf("月分输入错误!\n");
return;
}
printf("\n请输入日:");
scanf("%d",&day);
//printf("\n请输本年1月1号是星期几?:");
//scanf("%d",&j);
j=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+1)%7;//求1月1日是周几.
printf("\n");
if(((year%4==0)&&(year%100!=0))||(year%400==0)) x=29;
else x=28;
if(day<0 || (day>30 && (month==4 || month==6 || month==9 || month==11))
|| (day>31 && (month==1 || month==3 || month==5 || month==7 || month==8
|| month==10 || month==12)) || (day>x && month==2)){
printf("日期输入错误!\n");
return;
}
if(month==1) c=day;
else if(month==2) c=31+day;
else if(month==3) c=31+x+day;
else if(month==4) c=31+31+x+day;
else if(month==5) c=31+31+30+x+day;
else if(month==6) c=31+31+30+31+x+day;
else if(month==7) c=31+31+30+31+30+x+day;
else if(month==8) c=31+31+30+31+30+31+x+day;
else if(month==9) c=31+31+30+31+30+31+31+x+day;
else if(month==10) c=31+31+30+31+30+31+31+30+x+day;
else if(month==11) c=31+31+30+31+30+31+31+30+31+x+day;
else if(month==12) c=31+31+30+31+30+31+31+30+31+30+x+day;
num=((c-1)%7+j)%7;//这里要注意>7的情况,所以要再%7
if(x==28){
printf("今年不是闰年!\n");
printf("今天是今年的第%d周!\n",c/7+1);
printf("今天是%d年%d月%d日 星期%d\n",year,month,day,num);
printf("今天是%d年的第%d天\n",year,c);
}
else{
printf("今年是闰年!\n");
printf("今天是今年的第%d周!\n",c/7+1);
printf("今天是%d年%d月%d日 星期%d\n" ,year,month,day,num);
printf("今天是%d年的第%d天\n",year,c);
}
}
#include "stdio.h"//
void main(void){
int c,x,num,year,month,day,j=1,k=1;
printf("欢迎来到简易万年历\n\n");
printf("请输入年:");
scanf("%d",&year);
printf("\n请输入月:");
scanf("%d",&month);
if(month<0 || month>12){
printf("月分输入错误!\n");
return;
}
printf("\n请输入日:");
scanf("%d",&day);
//printf("\n请输本年1月1号是星期几?:");
//scanf("%d",&j);
j=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+1)%7;//求1月1日是周几.
printf("\n");
if(((year%4==0)&&(year%100!=0))||(year%400==0)) x=29;
else x=28;
if(day<0 || (day>30 && (month==4 || month==6 || month==9 || month==11))
|| (day>31 && (month==1 || month==3 || month==5 || month==7 || month==8
|| month==10 || month==12)) || (day>x && month==2)){
printf("日期输入错误!\n");
return;
}
if(month==1) c=day;
else if(month==2) c=31+day;
else if(month==3) c=31+x+day;
else if(month==4) c=31+31+x+day;
else if(month==5) c=31+31+30+x+day;
else if(month==6) c=31+31+30+31+x+day;
else if(month==7) c=31+31+30+31+30+x+day;
else if(month==8) c=31+31+30+31+30+31+x+day;
else if(month==9) c=31+31+30+31+30+31+31+x+day;
else if(month==10) c=31+31+30+31+30+31+31+30+x+day;
else if(month==11) c=31+31+30+31+30+31+31+30+31+x+day;
else if(month==12) c=31+31+30+31+30+31+31+30+31+30+x+day;
num=((c-1)%7+j)%7;//这里要注意>7的情况,所以要再%7
if(x==28){
printf("今年不是闰年!\n");
printf("今天是今年的第%d周!\n",c/7+1);
printf("今天是%d年%d月%d日 星期%d\n",year,month,day,num);
printf("今天是%d年的第%d天\n",year,c);
}
else{
printf("今年是闰年!\n");
printf("今天是今年的第%d周!\n",c/7+1);
printf("今天是%d年%d月%d日 星期%d\n" ,year,month,day,num);
printf("今天是%d年的第%d天\n",year,c);
}
}
更多追问追答
追问
运行 输完 日之后 为什么程序框就自动关闭了?是我电脑的问题吗 ?
还有前强两个return 后面为什么没有返回值?(这是我自己不懂 问一下)
还有 答辩要求至少100行 能帮我再加一点吗??我追加分
麻烦你了。。。。
追答
这里没有你说的“关闭”问题,运行很正常。就这么点问题要写100行吗?我加加看能到多少行!这里已放不下了,发到私信中,共4次才发完……
#include "stdio.h"//
void main(void){
int c;
int x;
int num;
int year;
int month;
int day;
int j=1;
int k=1;
printf("欢迎来到简易万年历\n\n");
printf("请输入年:");
scanf("%d",&year);
printf("\n请输入月:");
scanf("%d",&month);
if(month12){
printf("月分输入错误!\n");
return;
}
printf("\n请输入日:");
scanf("%d",&day);
//printf("\n请输本年1月1号是星期几?:");
//scanf("%d",&j);
year--;//以下求1月1日是周几.
j=year;
j+=year/4;
j-=year/100;
j+=year/400;
j+=1;
j%=7;
printf("\n");
year++;
if(((year%4==0)&&(year%100!=0))||(year%400==0))
x=29;
else x=28;
if(day30 && month==4){
printf("日期输入错误!\n");
return;
}
if(day>30 && month==6){
printf("日期输入错误!\n");
return;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
#include<stdlib.h>
int basic_y=2000,basic_m=1,basic_d=1,basic_td=6;
int isleapyear(int year)
{
return((year%4==0&&year%100!=0) || year%400==0);
}
int gettoday(int year,int month,int data)
{
int day_n[12]={31,59,90,120,151,181,212,243,273,304,334,365};
int day_l[12]={31,60,91,121,152,182,213,244,274,305,335,366};
int allday=0,i=basic_y;
for(i;i<year;i++)
{
if(isleapyear(i))
allday+=366;
else
allday+=365;
}
for(i=1;i<month;i++)
{
if(isleapyear(year))
{
allday+=day_l[month-2];
break;
}
if(!isleapyear(year))
{
allday+=day_n[month-2];
break;
}
}
allday+=data;
int temp;
temp=allday%7;
temp+=(basic_td-1);
if(temp>7)
temp-=7;
return temp;
}
void calder(int year,int month,int data)
{
if((year<2000) || (month>12||month<1) || (data>31||data<1))
exit(0);
int a[12]={31,28,31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int b[12]={31,29,31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int i,j=0,month_first,month_today,today;
char td[7][20]={"monday","tuesday","wensday","thursday","friday","saturday","sunday"};
month_first=gettoday(year,month,1);
printf(" mon tue wed thrs fri sat sud\n");
if(isleapyear(year))
{
for(i=1;i<month_first;i++)
{
printf("%4d",0),j++;
}
for(i=0;i<b[month-1];i++)
{
if(i<=9)
printf("%4d",i+1);
else
printf("%4d",i+1);
j++;
if(j==7)
{printf("\n");j=0;}
}
}
if(!isleapyear(year))
{
for(i=1;i<month_first;i++)
{
printf("%4d",0),j++;
}
for(i=0;i<a[month-1];i++)
{
if(i<=9)
printf("%4d",i+1);
else
printf("%4d",i+1);
j++;
if(j==7)
{printf("\n");j=0;}
}
}
today=data;
today=today%7;
today+=month_first;
if(today>7)
today-=7;
printf("\ntoday is:%d-%d-%d %s",year,month,data,td[today-2]);
}
int main(void)
{
int year,month,data;
printf("please input year,month and day like 2000:2:1 \n");
scanf("%d:%d:%d",&year,&month,&data);
calder(year,month,data);
printf("\n");
return 0;
}
//changchun
//毕业于内蒙古工业大学
#include<stdlib.h>
int basic_y=2000,basic_m=1,basic_d=1,basic_td=6;
int isleapyear(int year)
{
return((year%4==0&&year%100!=0) || year%400==0);
}
int gettoday(int year,int month,int data)
{
int day_n[12]={31,59,90,120,151,181,212,243,273,304,334,365};
int day_l[12]={31,60,91,121,152,182,213,244,274,305,335,366};
int allday=0,i=basic_y;
for(i;i<year;i++)
{
if(isleapyear(i))
allday+=366;
else
allday+=365;
}
for(i=1;i<month;i++)
{
if(isleapyear(year))
{
allday+=day_l[month-2];
break;
}
if(!isleapyear(year))
{
allday+=day_n[month-2];
break;
}
}
allday+=data;
int temp;
temp=allday%7;
temp+=(basic_td-1);
if(temp>7)
temp-=7;
return temp;
}
void calder(int year,int month,int data)
{
if((year<2000) || (month>12||month<1) || (data>31||data<1))
exit(0);
int a[12]={31,28,31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int b[12]={31,29,31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int i,j=0,month_first,month_today,today;
char td[7][20]={"monday","tuesday","wensday","thursday","friday","saturday","sunday"};
month_first=gettoday(year,month,1);
printf(" mon tue wed thrs fri sat sud\n");
if(isleapyear(year))
{
for(i=1;i<month_first;i++)
{
printf("%4d",0),j++;
}
for(i=0;i<b[month-1];i++)
{
if(i<=9)
printf("%4d",i+1);
else
printf("%4d",i+1);
j++;
if(j==7)
{printf("\n");j=0;}
}
}
if(!isleapyear(year))
{
for(i=1;i<month_first;i++)
{
printf("%4d",0),j++;
}
for(i=0;i<a[month-1];i++)
{
if(i<=9)
printf("%4d",i+1);
else
printf("%4d",i+1);
j++;
if(j==7)
{printf("\n");j=0;}
}
}
today=data;
today=today%7;
today+=month_first;
if(today>7)
today-=7;
printf("\ntoday is:%d-%d-%d %s",year,month,data,td[today-2]);
}
int main(void)
{
int year,month,data;
printf("please input year,month and day like 2000:2:1 \n");
scanf("%d:%d:%d",&year,&month,&data);
calder(year,month,data);
printf("\n");
return 0;
}
//changchun
//毕业于内蒙古工业大学
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个万年历,用switch ....case写比较简单
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询