码迷,mamicode.com
首页 > 编程语言 > 详细

C语言学习-4

时间:2015-05-03 14:37:27      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

/*
输入某年某月某日,判断这一天是这一年的第几天?
*/

#include<stdio.h>
int Leap(int);

int main(void)
{
    int year = 0, month = 0, day = 0, temp = 0; 
    printf("输入某年某月某日,输入样例如:2015,5,5\n");
    scanf("%d,%d,%d", &year, &month, &day);
    //判断平年还是闰年
    switch(month)
    {
        case 1:
            temp = 0;
            break;
        case 2:
            temp = 31;
            break;
        case 3:
            temp = 59;
            break;
        case 4:
            temp = 90;
            break;
        case 5:
            temp = 120;
            break;
        case 6:
            temp = 151;
            break;
        case 7:
            temp = 181;
            break;
        case 8:
            temp = 212;
            break;
        case 9:
            temp = 243;
            break;
        case 10:
            temp = 273;
            break;
        case 11:
            temp = 304;
            break;
        case 12:
            temp = 334;
            break;
    }
    if (Leap(year) == 1 && month > 2)
    {
        temp = temp + day + 1;
    }
    else
    {
        temp = temp + day;
    }
    printf("%d\n", temp); 
    return 0;
}

int Leap(int x)                //判断是否为闰年 
{
    if ((x%100!=0 && x%4==0) || (x%100==0 && x%400==0))
    {
        return 1;
    } 
    else
    {
        return 0;
    }
}

 

C语言学习-4

标签:

原文地址:http://www.cnblogs.com/L3i4c5x6/p/4473980.html

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