5.判断年份是否为闰年

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 int main()
 5 {
 6     int i,a[99999];
 7     for(i=0;i<2;i++)
 8     {
 9         scanf("%d",&a[i]);
10     }
11     for(i=0;i<2;i++)
12     {
13         if(a[i]%4!=0)
14         {
15             printf("a[i]=%d 不是闰年
",a[i]);
16         }
17 
18         else if(a[i]%4==0&&a[i]%100!=0)
19         {
20            printf("a[i]=%d 是闰年
",a[i]);
21         }
22 
23         else if(a[i]%400==0)
24         {
25            printf("a[i]=%d 是闰年 
",a[i]);
26         }
27 
28         else
29         {
30              printf("a[i]=%d不是闰年
",a[i]);
31         }
32 
33 
34     }
35     printf("
");
36     return 0;
37 }
#include <stdio.h>  //采用宏定义的方法
#define LEAP_YEAR(y) ((y%4==0&&y%100!=0)||(y%400==0))?'L':'N'  //L,N是字符需要加上单引号
int main()
{
    int  y;
    char a,L,N;
    scanf("%d",&y);
    a=LEAP_YEAR(y);
    printf("%c",a);
    return 0;

}
原文地址:https://www.cnblogs.com/spore/p/10252427.html