Learn Programming and technology with ease @ developerpublish.com

HomeC ProgrammingC Program to find if the Given Year is Leap Year or Not

# C Program to find if the Given Year is Leap Year or Not

This C program determines whether a given year is a leap year or not. A leap year is a year that is exactly divisible by 4, except for years that are exactly divisible by 100. However, years that are divisible by 400 are leap years.

## Problem statement

Write a C program to find if the given year is a leap year or not.

## C Program to find if the Given Year is Leap Year or Not

```#include <stdio.h>

int isLeapYear(int year) {
if (year % 400 == 0) {
return 1;
} else if (year % 100 == 0) {
return 0;
} else if (year % 4 == 0) {
return 1;
} else {
return 0;
}
}

int main() {
int year;

printf("Leap Year Checker\n");
printf("-----------------\n");

printf("Enter a year: ");
scanf("%d", &year);

if (isLeapYear(year)) {
printf("%d is a leap year.\n", year);
} else {
printf("%d is not a leap year.\n", year);
}

return 0;
}
```

## How it works?

1. The program starts by including the necessary header file `stdio.h`, which provides input/output functions.
2. The function `is LeapYear()` takes an integer `year` as input and returns 1 if the year is a leap year, and 0 if itâ€™s not.
3. Inside the `is LeapYear()` function, it checks the following conditions:
• If the year is divisible by 400, it is a leap year.
• If the year is divisible by 100, it is not a leap year.
• If the year is divisible by 4, it is a leap year.
• If none of the above conditions are met, it is not a leap year.
4. In the `main()` function:
• It prompts the user to enter a year.
• The input is stored in the `year` variable using the `scanf()` function.
• It calls the `isLeapYear()` function with the `year` as an argument to determine if itâ€™s a leap year or not.
• Finally, it prints the result based on the returned value.

## Input/Output

Share:

### You May Also Like

#### C Program to Find Volume and Surface Area of Sphere

This C program calculates the volume and surface area of a sphere using its radius. A sphere is a three-dimensional...

#### C Program to Convert Roman Number to Decimal Number

This C program converts a Roman numeral to a decimal number. Roman numerals are a system of numerical notation used...

#### C Program to Calculate the Value of sin(x)

This C program calculates the value of sin(x) using the Taylor series expansion. The Taylor series expansion is a mathematical...