4. Determine the leap year

/*

Enter a year number from the keyboard to determine whether it is a normal year or a leap year.

Requirements:
1. The number of years cannot be less than 1900.
2. Letters cannot be entered for
the number of years. 3. If the number of years entered does not meet the above conditions, a prompt will be prompted to re-enter
:
1. A year that is divisible by 4 but not divisible by 100 is a leap year ,
or a year divisible by 400 is also a leap year, otherwise it is an ordinary year.
*/
#include "stdio.h"
void main()
{
int y,n;

n=0; //First store a 0 for n to indicate that y does not receive correct data
printf("Please enter a year number:") ;
yy:n=scanf("%d",&y);
if(n!=1||y<1900)
{
printf("The year number is entered incorrectly, please retype:");
fflush(stdin);
goto yy;
}

if(y%4==0&&y%100!=0||y%400==0)
printf("\n%d is a leap year\n",y);
else
printf("\n%d Year is an ordinary year\n",y);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325894356&siteId=291194637