实现一个函数判断是不是闰年

实现一个函数判断是不是闰年
普通闰年:不能被100整除,但能被4整除
世纪闰年:能被100整除,能被400整除

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void LeapYear(int n) {
	if (n % 100 == 0) {
		if (n % 400 == 0) {
			return 1;
		}
		return 0;
	}
	else {
		if (n % 4 == 0) {
			return 1;
		}
		return 0;
	}
}
int main() {
	int n = 0;
	printf("请输入年份:");
	scanf("%d", &n);
	if (LeapYear) {
		printf("是闰年");
	}
	else {
		printf("不是闰年");
	}
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Amoralmmm/article/details/93843955