平年闰年判断 新手入门

116 阅读1分钟
#include<stdio.h>
int judge_year(int x)
{
	if (x % 4 == 0 && x % 100 != 0 || x % 400 == 0)
	{
		return 1;
	}
	else
	{
		return 0;
	}
	
}

int main()
{
	int year = 0;
	printf("请输入年份:");
	scanf_s("%d", &year);
	
	if (judge_year(year) == 1)
	{
		printf("%d年是闰年", year);
	}
	else
	{
		printf("%d年不是闰年", year);
	}
	return 0;
}

修正:在judge_year后面的if把括号补上

if ((x % 4 == 0 && x % 100 != 0) || (x % 400 == 0))