c语言作业编写程序输入某年某月某天,求这是这一年的第几天

这是我想的方法,觉得很冗长。且暂时没有分辨平年和闰年的办法。求各位大神赐教... 这是我想的方法,觉得很冗长。且暂时没有分辨平年和闰年的办法。求各位大神赐教 展开
 我来答
newchinays
2017-11-11 · TA获得超过1173个赞
知道小有建树答主
回答量:1238
采纳率:48%
帮助的人:441万
展开全部
#include<stdio.h>
 
int main()
{
    int sum;
    int i,t,c;
    int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    int year,mon,day;
    printf("Please enter the times you want to calculate(eg.2):");
    scanf("%d",&t);
    for(c=0;c<t;c++)
    {
        sum=0;
        printf("\n");
        printf("Please enter the date(eg.2016/06/20):");
        scanf("%d/%d/%d",&year,&mon,&day);
 
        if( (year%400==0) || ((year%4==0)&&(year%100!=0)) )
            month[1]=29;
        for(i=0;i<mon-1;i++)
            sum=sum+month[i];
 
        sum=sum+day;
        printf("It's the %dth day in this year.\n",sum);
    }
    return 0;
}
追问
还没学到for语句
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式