<pre name="code" class="objc"><span style="color:#ff6666;">#include <stdio.h>

int main(int argc, const char * argv[])
{
    //用switch语句计算出这一天是这一年的第几天。

    int year;
    int mouth;
    int day;
    int isRun = 1;
    int total;
    printf("请输入年,月,日:\n");
    scanf("%i,%i,%i",&year,&mouth,&day);

    //如果是闰年的话,isRun是0
    if(year % 100 == 0 && year % 4 == 0){
        isRun = 1;
    }else isRun = 0;
    
    total = 0;
    
    switch (mouth - 1)
    {
        case 12:
            total += 31;
        case 11:
            total += 30;
        case 10:
            total += 31;
        case 9:
            total += 30;
        case 8:
            total += 31;
        case 7:
            total += 31;
        case 6:
            total += 30;
        case 5:
            total += 31;
        case 4:
            total += 30;
        case 3:
            total += 31;
        case 2:
            total += 28 + isRun;//如果是闰年,isRun的值是1,否则是0;
        case 1:
            total += 31;
            total = total + day;
            break;
    }
    printf("%d年,%d月,%d日是这一年的第%i天\n",year,mouth,day,total);
    
    return 0;
}
</span>






版权声明:本文为yuan_will原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/yuan_will/article/details/39322679