40

c语言 简单问题 怎么改 不懂报错 1111111111111111

图片说明

#include <stdio.h>
#include<stdlib.h>

int  DayofYear(int year, int month, int day);
void  MonthDay(int year, int yearDay, int *pMonth, int *pDay);


int main()
{
    int num;
    int year,month,day,yearDay;
    int a;
    int *pMonth,*pDay;
    printf("1. year/month/day -> yearDay\n2. yearDay -> year/month/day\n3. Exit\nPlease enter your choice:");
    scanf("%d",&num);
    switch(num)
    {
    case 1:
        printf("Please enter year, month, day:");
        scanf("%d,%d,%d",&year,&month,&day);
        a = DayofYear(year, month, day);
        printf("yearDay = %d\n",a);
        break;
    case 2:
        printf("Please enter year, yearDay:");
        scanf("%d,%d",&year,&yearDay);
        MonthDay(year, yearDay, &month, &day);
        break;
    case 3:
        break;
    }

    int  DayofYear(int year, int month, int day)
    {
        int a=0,i,m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
        if(year%4==0&&year%100!=0||year%400==0)
        {
            m[2]=29;
        }
        for(i=1;i<month;i++)
        {
            a += m[i];
        }
        a = a + day;
        return a;
    }
    void  MonthDay(int year, int yearDay, int *pMonth, int *pDay)
    {
        *pMonth = 0;
        *pDay = 0;
        int i = 1;
        int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
        int s = 0;
        if((year%4 == 0&&year%100 != 0)||(year%400 == 0))
        {
            m[3] = 29;
        }
        do
        {
            s += m[i];
            i++;
        }while(s < yearDay);
        *pMonth = (i-1);
        *pDay = yearDay - (s-m[i]);
        printf("month = %d, day = %d\n",*pMonth,*pDay);
    }



}



查看全部
weixin_43408535
-cfyjbjonn
2019/03/17 01:08
  • c语言
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复