第十六周-计算该日在本年中是第几天

来源:互联网 发布:ip网络摄像头监控软件 编辑:程序博客网 时间:2024/05/10 14:24
#include <stdio.h>#include <stdlib.h>typedef struct{    int year;    int month;    int day;} y_m_d;int main(){    y_m_d date;    int days(y_m_d);    //y_m_d是自定义的类型    int day_sum;    scanf("%d%d%d",&date.year,&date.month,&date.day);    day_sum=days(date);    printf("%d\n",day_sum);    return 0;}int days(y_m_d date){    int i,count=date.day;    for(i=1; i<date.month; ++i)    {        switch(i)        {        case 2:            count+=((date.year%4==0&&date.year%100!=0)||date.year%400==0)?29:28;            break;        case 4:        case 6:        case 9:        case 11:            count+=30;            break;        default:            count+=31;            break;        }    }    return count;}

0 0
原创粉丝点击