Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Language Examples - Checking for a Leap Year

C Language Examples - Checking for a Leap Year

C Language Examples C Language Examples

The user enters a year and determines whether it is a leap year.

Example

#include

<

stdio.h

int

main

(

)

{

int

year

;

printf

(

"

Enter a year:

"

)

;

scanf

(

"

%d

"

,&

year

)

;

if

(

year

%

4

==

0

)

{

if

(

year

%

100

==

0

)

{

// Here, if divisible by 400, it is a leap year

if

(

year

%

400

==

0

)

printf

(

"

%d is a leap year

"

,

year

)

;

else

printf

(

"

%d is not a leap year

"

,

year

)

;

}

else

printf

(

"

%d is a leap year

"

,

year

)

;

}

else

printf

(

"

%d is not a leap year

"

,

year

)

;

return

0

;

}

Running result:



输入年份: 1990

1990 不是闰

C Language Examples C Language Examples