• 闰年分普通闰年和世纪闰年,普通闰年不能被100整除但可以被4整除,世纪闰年能被100整除且可以被400整除。(1700能被100整除,也能被4整除,但不是闰年,并不是能被4整除就是闰年哦)

Description

输入一个年份值,判断这一年是否闰年。

Input

一个正整数。

Output

按照样例输出格式输出相关信息。

Sample Input 1

2020

Sample Output 1

2020 is a leap year!

Sample Input 2

2021

Sample Output 2

2021 isn't a leap year!
#include <stdio.h>
#include<math.h>
int main()
{
	int n;
	scanf("%d", &n);
	if (n % 100 != 0 && n % 4 == 0)//不能被100整除但可以被4整除
		printf("%d is a leap year!", n);
	else if (n % 400 == 0)//能被400整除
		printf("%d is a leap year!", n);
	else printf("%d isn't a leap year!", n);

	return 0;
}

 

更多推荐

闰年(C语言实现)