Epsilon0822
Epsilon LTT
采纳率50%
2020-12-30 10:00

这个万年历程序该怎么修改呢?

50
已采纳

#include <stdio.h>
int Year,Month,Day,week_day;
double Days_interval;//不包括那一月的间隔天数
int main()
{
    printf("请输入年月日:");
    scanf("%d%d%d",&Year,&Month,&Day);
    double Days_Interval();//总天数间隔
    int SX();//生肖;
    int Month_days();//判断那个月有多少天
    int Week_day();//每月1号是星期几
    void print();
    return 0;
}

double Days_Interval()//计算总天数间隔
{
    int year=1900,month=1;
    double Days_Interval=0;
    for(year=1900;year<Year;year++)
    {
        if ((Year % 4 == 0 && Year %100 != 0) || (Year % 400 == 0))
        {
            Days_Interval+=366;
        }
        else
        {
            Days_Interval+=365;
        }
    }
    for(month=1;month<Month;month++)
    {
        switch(month)
        {
        case 1:Days_Interval+=31;break;
        case 2:if((Year % 4 == 0 && Year %100 != 0) || (Year % 400 == 0))
               {
                    Days_Interval+=29;
               }
                else
                {
                    Days_Interval+=28;
                }break;
        case 3:Days_Interval+=31;break;
        case 4:Days_Interval+=30;break;
        case 5:Days_Interval+=31;break;
        case 6:Days_Interval+=30;break;
        case 7:Days_Interval+=31;break;
        case 8:Days_Interval+=31;break;
        case 9:Days_Interval+=30;break;
        case 10:Days_Interval+=31;break;
        case 11:Days_Interval+=30;break;
        case 12:Days_Interval+=31;break;
    }
    Days_interval=Days_Interval;
    Days_Interval+=Day;
}
int Month_days()//判断这个月有多少天
{
    if(Month==2)
    {
        if((Year % 4 == 0 && Year %100 != 0) || (Year % 400 == 0))
            Month_days=29;
        else Month_days=28;
    }
    else if(Month==1||Month==3||Month==5||Month==7||Month==8||Month==10||Month==12)
        Month_days=31;
    else Month_days=30;
    return 0;
}

int Week_day()//计算每月1号是星期几
{
    Days_interval+=1;
    week_day=Days_interval%7;
    return (week_day);
}
int SX()//判断生肖
{
    int x;
    x=(Year-1900)%12;
    switch(x)
    {
    case 0:printf("%d年是鼠年",Year);break;
    case 1:printf("%d年是牛年",Year);break;
    case 2:printf("%d年是虎年",Year);break;
    case 3:printf("%d年是兔年",Year);break;
    case 4:printf("%d年是龙年",Year);break;
    case 5:printf("%d年是蛇年",Year);break;
    case 6:printf("%d年是马年",Year);break;
    case 7:printf("%d年是羊年",Year);break;
    case 8:printf("%d年是猴年",Year);break;
    case 9:printf("%d年是鸡年",Year);break;
    case 10:printf("%d年是狗年",Year);break;
    case 11:printf("%d年是猪年",Year);break;
    }
    return 0;
}
void print()
{
    int i=1;
    print("一    二    三    四    五    六    日    \n");
    for(i=1;i<week_day;i++)
        printf("\t");
    for(i=1;i<Month_days;i++)
    {
        printf("%4d",i);
        week_day++;
        if (week_day%7==0&&i<=Month_days)
        printf("\n");
    }
}
 

 

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

8条回答

  • bosaidongmomo bosaidongmomo 3月前
    #include <stdio.h>
    int Year, Month, Day, week_day;
    double Days_interval;//不包括那一月的间隔天数
    int m_month_days;
    int main()
    {
    	printf("请输入年月日:");
    	scanf("%d%d%d", &Year, &Month, &Day);
    	double Days_Interval();//总天数间隔
    	int SX();//生肖;
    	int Month_days();//判断那个月有多少天
    	int Week_day();//每月1号是星期几
    	void print();
    	Days_Interval();
    	SX();
    	Month_days();
    	Week_day();
    	print();
    	return 0;
    }
    
    double Days_Interval()//计算总天数间隔
    {
    	int year = 1900, month = 1;
    	double Days_Interval = 0;
    	for (year = 1900; year < Year; year++)
    	{
    		if ((Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0))
    		{
    			Days_Interval += 366;
    		}
    		else
    		{
    			Days_Interval += 365;
    		}
    	}
    	for (month = 1; month < Month; month++)
    	{
    		switch (month)
    		{
    		case 1:Days_Interval += 31; break;
    		case 2:if ((Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0))
    		{
    			Days_Interval += 29;
    		}
    			   else
    			   {
    				   Days_Interval += 28;
    			   }break;
    		case 3:Days_Interval += 31; break;
    		case 4:Days_Interval += 30; break;
    		case 5:Days_Interval += 31; break;
    		case 6:Days_Interval += 30; break;
    		case 7:Days_Interval += 31; break;
    		case 8:Days_Interval += 31; break;
    		case 9:Days_Interval += 30; break;
    		case 10:Days_Interval += 31; break;
    		case 11:Days_Interval += 30; break;
    		case 12:Days_Interval += 31; break;
    		}
    		Days_interval = Days_Interval;
    		Days_Interval += Day;
    	}
    	return Days_Interval;
    }
    	int Month_days()//判断这个月有多少天
    	{
    		if (Month == 2)
    		{
    			if ((Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0))
    				m_month_days = 29;
    			else m_month_days = 28;
    		}
    		else if (Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12)
    			m_month_days = 31;
    		else m_month_days = 30;
    		return 0;
    	}
    
    	int Week_day()//计算每月1号是星期几
    	{
    		Days_interval += 1;
    		week_day = (int)Days_interval % 7;
    		return (week_day);
    	}
    	int SX()//判断生肖
    	{
    		int x;
    		x = (Year - 1900) % 12;
    		switch (x)
    		{
    		case 0:printf("%d年是鼠年", Year); break;
    		case 1:printf("%d年是牛年", Year); break;
    		case 2:printf("%d年是虎年", Year); break;
    		case 3:printf("%d年是兔年", Year); break;
    		case 4:printf("%d年是龙年", Year); break;
    		case 5:printf("%d年是蛇年", Year); break;
    		case 6:printf("%d年是马年", Year); break;
    		case 7:printf("%d年是羊年", Year); break;
    		case 8:printf("%d年是猴年", Year); break;
    		case 9:printf("%d年是鸡年", Year); break;
    		case 10:printf("%d年是狗年", Year); break;
    		case 11:printf("%d年是猪年", Year); break;
    		}
    		return 0;
    	}
    	void print()
    	{
    		int i = 1;
    		printf("一    二    三    四    五    六    日    \n");
    		for (i = 1; i<week_day; i++)
    			printf("\t");
    		for (i = 1; i<m_month_days; i++)
    		{
    			printf("%4d", i);
    			week_day++;
    			if (week_day % 7 == 0 && i <= m_month_days)
    				printf("\n");
    		}
    	}
    点赞 评论 复制链接分享
  • Epsilon0822 Epsilon LTT 1月前

    最后改了是这样的(突然想起来要完整一点哈哈哈

    	
    #include <stdio.h>
    int Year,Month,Day,week_day;
    double Days_interval;//不包括那一月的间隔天数
    int month_days;
    int main()
    {
    	printf("请输入年月日:");
    	scanf("%d%d%d", &Year, &Month, &Day);
    	double Days_Interval();//总天数间隔
    	int SX();//生肖;
    	int Month_days();//判断那个月有多少天
    	int Week_day();//每月1号是星期几
    	void print();
    	Days_Interval();
    	SX();
    	Month_days();
    	Week_day();
    	print();
    	return 0;
    }
     
    double Days_Interval()//计算总天数间隔
    {
    	int year=1900, month=1;
    	double Days_Interval=0;
    	for (year=1900;year<Year;year++)
    	{
    		if ((Year%4==0 && Year%100!= 0)||(Year%400==0))
    		{
    			Days_Interval+=366;
    		}
    		else
    		{
    			Days_Interval+=365;
    		}
    	}
    	for (month=1;month<Month;month++)
    	{
    		switch (month)
    		{
    		case 1:Days_Interval+=31;break;
    		case 2:if ((Year%4==0 && Year%100!=0) || (Year%400==0))
    		{
    			Days_Interval+=29;
    		}
    			   else
    			   {
    				   Days_Interval+=28;
    			   }break;
    		case 3:Days_Interval+=31; break;
    		case 4:Days_Interval+=30; break;
    		case 5:Days_Interval+=31; break;
    		case 6:Days_Interval+=30; break;
    		case 7:Days_Interval+=31; break;
    		case 8:Days_Interval+=31; break;
    		case 9:Days_Interval+=30; break;
    		case 10:Days_Interval+=31; break;
    		case 11:Days_Interval+=30; break;
    		case 12:Days_Interval+=31; break;
    		}
    		Days_interval=Days_Interval;
    
    	}
    	return (Days_Interval);
    }
    	int Month_days()//判断这个月有多少天
    	{
    		if (Month==2)
    		{
    			if ((Year%4==0 && Year%100!=0)||(Year%400==0))
    				month_days=29;
    			else month_days=28;
    		}
    		else if (Month==1||Month==3||Month==5||Month==7||Month==8||Month==10||Month==12)
    			month_days = 31;
    		else month_days = 30;
    		return 0;
    	}
     
    	int Week_day()//计算每月1号是星期几
    	{
    		Days_interval+=1;
    		week_day=(int)Days_interval%7;
    		return (week_day);
    	}
    	int SX()//判断生肖
    	{
    		int x;
    		x = (Year-1900) % 12;
    		switch (x)
    		{
    		case 0:printf("%d年是鼠年\n", Year); break;
    		case 1:printf("%d年是牛年\n", Year); break;
    		case 2:printf("%d年是虎年\n", Year); break;
    		case 3:printf("%d年是兔年\n", Year); break;
    		case 4:printf("%d年是龙年\n", Year); break;
    		case 5:printf("%d年是蛇年\n", Year); break;
    		case 6:printf("%d年是马年\n", Year); break;
    		case 7:printf("%d年是羊年\n", Year); break;
    		case 8:printf("%d年是猴年\n", Year); break;
    		case 9:printf("%d年是鸡年\n", Year); break;
    		case 10:printf("%d年是狗年\n", Year); break;
    		case 11:printf("%d年是猪年\n", Year); break;
    		}
    		printf("以下是%d年%d月的日历\n",Year,Month);
    		return 0;
    	}
    void print()
    	{
    		int i = 1;
    		printf("  一  二  三  四  五  六  日\n");
    		for (i=1;i<week_day;i++)
    			printf("    ");
            if(week_day==0)
                for (i=0;i<6;i++)
    			printf("    ");
            week_day--;
    		for (i=1;i<=month_days;i++)
    		{
    			printf("%4d", i);
    			week_day++;
    			if (week_day%7==0 && i<=month_days)
    				printf("\n");
    		}
    		printf("\n");
    	}
    

    点赞 评论 复制链接分享
  • bosaidongmomo bosaidongmomo 3月前

    第62行,不要加你输入的天数

    点赞 评论 复制链接分享
  • Epsilon0822 Epsilon LTT 3月前

    比如这样

    点赞 评论 复制链接分享
  • Epsilon0822 Epsilon LTT 3月前

    就是接下来的每个第一天总是和一号对齐

    点赞 评论 复制链接分享
  • Epsilon0822 Epsilon LTT 3月前

    谢谢!!可是运行结果有一点奇怪,就是日历表打出来有点不太对而且没对齐,方便帮我看看是哪个代码出问题了么?

    点赞 评论 复制链接分享
  • bosaidongmomo bosaidongmomo 3月前

    函数名和变量名最好不要同名

    点赞 评论 复制链接分享
  • bosaidongmomo bosaidongmomo 3月前

    函数定义和函数调用不一样

    点赞 评论 复制链接分享