码迷,mamicode.com
首页 > 其他好文 > 详细

日期转换

时间:2014-07-22 22:47:13      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   for   re   c   

printf("请输入查询方式\n");
    printf("输入1:表示查询第几天(输入年月日)\n");
    printf("输入2:表示查询具体的日期(输入年和天数)\n");
    int n=2, year=2001,month=12,day=31,dayOfTheYear=4;
    int numOfMonth[12]={31,29,31,30,31,30,31,31,30,31,30,31};
    int numOfMonth1[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    
    //scanf("%d",&n);
    if (n==1)
    {
        printf("请输入年月日\n");
        scanf("%d %d %d",&year,&month,&day);
        int a=0;

        if ([self isRN:year])
        {
            for (int i=0; i<month-1; i++)
            {
                a+=numOfMonth[i];
            }
            a+=day;
        }
        else        {
            for (int i=0; i<month-1; i++)
            {
                a+=numOfMonth1[i];
            }
            a+=day;
        }
        printf("%d年%d月%d日是这一年的第%d天",year,month,day,a);
    }
    else  if(n==2)
    {
        //printf("请输入年和第几天");
       // scanf("%d %d ",&year,&dayOfTheYear);
        if ([self isRN:year])
        {
            int a=0;

            for (int i=0; i<12; i++)
            {
                if (dayOfTheYear<31)
                {
                    printf("%d第%d天是这一年的1月%d日",year, dayOfTheYear,dayOfTheYear);
                    break;
                }
                a+=numOfMonth[i];
                if (dayOfTheYear>a&&dayOfTheYear<=(a+numOfMonth[i+1]))
                {
                    printf("%d第%d天是这一年的%d月%d日",year, dayOfTheYear,i+2,(dayOfTheYear-a));
                    break;
                }
            }
        }
        else
        {int a=0;
            
            for (int i=0; i<12; i++)
            {
                if (dayOfTheYear<31)
                {
                    printf("%d第%d天是这一年的1月%d日",year, dayOfTheYear,dayOfTheYear);
                    break;
                }
                a+=numOfMonth1[i];
                if (dayOfTheYear>a&&dayOfTheYear<=(a+numOfMonth1[i+1]))
                {
                    printf("%d第%d天是这一年的%d月%d日",year, dayOfTheYear,i+2,(dayOfTheYear-a));
                    break;
                }
            }
        }
    }

日期转换,布布扣,bubuko.com

日期转换

标签:style   blog   color   for   re   c   

原文地址:http://www.cnblogs.com/lidongq/p/3859714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!