/ 科创班 /

记录详情

Wrong Answer

/in/foo.c: In function 'leap':
/in/foo.c:6:15: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     if (a%4==0&&a%100!=0||a%400==0)               
         ~~~~~~^~~~~~~~~~
# 状态 耗时 内存占用
#1 Wrong Answer 1ms 256.0 KiB

代码

#include<stdio.h>
int leap(int a)                                     

{

    if (a%4==0&&a%100!=0||a%400==0)               

        return 1;                                   

    else

        return 0;                                   

}

 

int number(int year, int m, int d) 

{

    int sum = 0, i, a[12] ={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};                    

    int b[12] ={31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};                       

    if (leap(year) == 1)                           

        for (i = 0; i < m - 1; i++)

            sum += b[i];                           

    else

        for (i = 0; i < m - 1; i++)

            sum += a[i];                           

    sum += d;                                        

    return sum;                                      
}

 
int main()

{

    int year, month, day, n;                             

    printf("请输入年月日\n");
    scanf("%d%d%d", &year, &month, &day);            

    n = number(year, month, day);                        

    printf("第%d天\n", n);

}

信息

递交者
类型
递交
题目
给出年、月、日,计算该日是该年的第几天
题目数据
下载
语言
C
递交时间
2018-06-20 22:20:01
评测时间
2018-06-20 22:20:01
评测机
分数
0
总耗时
1ms
峰值内存
256.0 KiB