输入年月份,计算今天是今年的第几天?


C代码



today.c

):

#include<stdio.h> 
void main() 
{ 
    int year,month,day,days,i,d; 
    printf("请输入年,月,日:\n"); 
    scanf("%d,%d,%d",&year,&month,&day); 
    days=0; 
    for(i=1;i<month;i++) 
    { 
        switch(i) 
        { 
            case 1: 
            case 3: 
            case 5: 
            case 7: 
            case 8: 
            case 10: 
            case 12:d=31;break; 
            case 4: 
            case 6: 
            case 9: 
            case 11:d=30;break; 
            case 2:if(year%4==0&&year%100!=0||year%400==0) 
                       d=29; 
                   else d=28; 
        } 
        days+=d; 
    } 
    printf("%d年%d月%d日是这一年的第%d天。\n",year,month,day,days+day); 
}


gcc编译:


gcc -c today.c && ./a.out


运行结果:


2^8 = 256 mod 365 = 9.13 (


程序猿节日快乐!^_^