C language input an integer that represents the year, judge whether the year is a leap year, the result of the judgment is displayed on the screen

#include<stdio.h>
void main()
{
    
    
	int year;
	printf("请输入一个年份:\n");
	scanf("%d",&year);
	if(year%4==0&&year%100!=0||year%400==0)
	{
    
    
		printf("该年份是闰年:%d\n",year);
	}
	else
	{
    
    
		printf("该年份不是闰年:%d\n",year);
	}
}

The program uses an if conditional statement. If the condition of a leap year is met, the output of the year is a leap year, otherwise the condition is not established.
Attachment: the conditions for judging leap years. Ordinary leap year: Gregorian calendar year is a multiple of 4 and not a multiple of 100. Century leap year: The Gregorian calendar year is a whole hundred, and it must be a multiple of 400 to be a century leap year.
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_53521757/article/details/111311828