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

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int Isleap(int a)  //建立一个函数,如果是闰年就返回1,不是就返回-1
{
	
	if (a % 4 != 0)
		return -1;
	else
		if (a % 100 != 0)
			return 1;
		else
		{
			if (a % 400 == 0)
				return 1;
			else
				return -1;
		}
	
}
void main()
{
	int a;
	printf("请输入一个数字:");
	scanf("%d", &a);
	int temp = Isleap(a);
	if (temp == 1)
		printf("是闰年!");
	if (temp == -1)
		printf("不是闰年!");
	system("pause");
}

猜你喜欢

转载自blog.csdn.net/qq_43765564/article/details/84928276