---
title: "Check leap year"
subject: "Computer Programming"
chapter: 5
key: "semester_1/computer_programming:leap-year-program"
source: https://www.bctengineer.com/q/semester_1/computer_programming/leap-year-program
site: BCT Engineering
---

# Check leap year

Computer Programming · Chapter 5: Control statements

- Asked in: 2071 Shrawan, 7 marks
- Video: [Special Programs in C − Check Leap Year](https://www.youtube.com/watch?v=rkR_04FIr7U) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/leap-year-program
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-5

## Question

Write a program to find whether a year is leap or not.

## Short answer

A year is leap if divisible by 4 but not 100, or divisible by 400. Check condition and print result.

## Answer

A year is a leap year if it is divisible by 4 but not by 100, or if it is divisible by 400. Hence 2024 and 2000 are leap years; 1900 and 2023 are not.

```c
#include <stdio.h>
int main(void)
{
    int year;
    printf("Enter a year: ");
    scanf("%d", &year);
    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
        printf("%d is a leap year\n", year);
    else
        printf("%d is not a leap year\n", year);
    return 0;
}
```
Output for 2024:
```text
Enter a year: 2024 is a leap year
```
Other test results: 2000 is a leap year, 1900 is not, 2023 is not.

#### Explanation
- `year % 4 == 0 && year % 100 != 0` covers ordinary leap years (2024).
- `year % 400 == 0` covers century years such as 2000; 1900 is divisible by 100 but not by 400, so it is not leap.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which condition correctly tests leap year?
   A. y%4==0 || y%100==0
   B. (y%4==0 && y%100!=0) || y%400==0
   C. y%4==0 && y%400==0
   D. y%100==0 && y%4!=0
   Answer: B. Divisible by 4 not 100, or by 400. (Key point: Rule)

2. Why is 1900 not leap?
   A. Not divisible by 4
   B. Odd
   C. Divisible by 100 but not 400
   D. Too small
   Answer: C. Century rule. (Key point: 1900)

3. Why is 2000 leap?
   A. Not by 100
   B. Not by 4
   C. Even
   D. Divisible by 400
   Answer: D. 400 rule overrides. (Key point: 2000)

4. Why not 2023?
   A. Not divisible by 4
   B. Divisible by 100
   C. Not by 400 only
   D. Prime
   Answer: A. 2023 % 4 = 3. (Key point: 2023)

## Related in Computer Programming

- [Check triangular number](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Atriangular-number) — Computer Programming, chapter 5
- [nth Fibonacci term prime check](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afibonacci-nth-prime) — Computer Programming, chapter 6
- [Check string consists of alphabet only](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astring-alphabet-check) — Computer Programming, chapter 7
- [Palindrome check in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-palindrome) — Computer Programming, chapter 11
- [Armstrong number using recursion](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aarmstrong-recursive) — Computer Programming, chapter 6
- [Palindrome string using function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apalindrome-string-function) — Computer Programming, chapter 7

## Related in other subjects

- [JFET ID and VDS (VP -5.5 V, IDSS 10 mA), pinch-off check](https://www.bctengineer.com/question.md?key=semester_3%2Felectronics_devices_and_circuit%3Ajfet-self-bias-vp-5p5) — Electronics Devices and Circuit, chapter 3, asked 3×
- [JFET ID and VDS (VP -3.5 V, IDSS 10 mA), pinch-off check](https://www.bctengineer.com/question.md?key=semester_3%2Felectronics_devices_and_circuit%3Ajfet-self-bias-vp-3p5) — Electronics Devices and Circuit, chapter 3, asked 3×
- [Check y(t) = x(t-2) + x(2-t)](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Acheck-xt-2-plus-x2-t) — Data Communication, chapter 2
- [Check linearity/TI: log(x(t)), t·x(t)](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Acheck-log-xt-and-t-xt) — Data Communication, chapter 2
