C language to determine whether a year is a leap year various implementation program codes
1. Calculation principles for leap years in the Gregorian calendar (according to a tropical year, 365 days, 5 hours, 48 minutes, 45.5 seconds)
1) A leap year is an ordinary year that is divisible by 4 but not divisible by 100. (For example, 2004 is a leap year, 1900 is not a leap year)
2) If the century year is divisible by 400 , it is a leap year. (e.g. 2000 is a leap year, 1900 is not a leap year)
3) For a year with a large value, if the year is divisible by 3200 and divisible by 172800, it is a leap year. For example, the year 172800 is a leap year, and the year 86400 is not a leap year (because it is divisible by 3200, but not divisible by 172800) (this is calculated according to 365 days in a tropical year, 5h48'45.5'').
2. Gregorian leap year program judgment statement
if( ((0 == year%4)&&(0 != year%100)) ||(0 == year %400) )
{
//yeat that satisfies this condition is a leap year.
}
3. Gregorian leap year program code ( collected from the Internet by www.169it.com )
Gregorian leap year implementation code 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include <stdio.h>
void
main()
{
int
year,leap;
scanf
(
"%d"
,&year);
if
(year%4==0)
{
if
(year%100!=0)
leap=1;
else
{
if
(year%400==0)
leap=1;
else
leap=0;
}
}
if
(leap==1)
printf
(
"%d是闰年n"
,year);
else
printf
(
"%d不是闰年n"
,year);}
|
Gregorian leap year implementation code 2:
1
2
3
4
5
6
7
8
9
10
|
#include <stdio.h>
void
main()
{
int
year,leap;
scanf
(
"%d"
,&year);
if
(year%400==0||year%4==0&&year%100!=0)
printf
(
"%d是闰年n"
,year);
else
printf
(
"%d不是闰年n"
,year);
}
|
Gregorian leap year implementation code 3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include<stdio.h>
int
main()
{
int
year;
year=1900;
while
(year<=2000)
{
if
(year%400==0||year%4==0&&year%100!=0)
{
printf
(
"%d是闰年n"
,year);
year++;
}
else
year++;
}
return
0;
}
|
The above code is for reference only.