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

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int Isleap(int year) {
	int leap = 0;
	if (year % 400 == 0){
		leap = 1; 
	}
	else if(year % 4 == 0 && year % 100 != 0) {
		leap = 1;
	}
	else {
		leap = 0; 
	}
	return leap;

}
int main() {
	int year=0;

	printf("输入一个年份,判断他是不是闰年:");
		scanf("%d", &year);
		int leap = Isleap(year);
		if (leap == 1) {
			printf("%d 年是闰年!\n",year);
		}
		else {
			printf("%d 年不是闰年!\n",year);
		}
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43267837/article/details/88779130