判断年份是否为闰年

119 阅读1分钟

编写一个程序,判定某个年份是否为闰年。年份满足如下条件,即是闰年

  • (1)year 是 400 的整数倍:year % 400 == 0
  • (2)能被4整除,但不能被100整除:year % 4 == 0 && year % 100 !=0
#include<stdio.h>

int main(){
 
    printf("enter year:");
    int year;
    scanf("%d",&year);
    if( year % 400 == 0 ||(year % 4 ==0 && year % 100 !=0)){
        printf("%d is a leap year\n",year);
    }else
        printf("%d is not a leap year\n",year);
    return 0;
}