The Program in C that checks whether a year is a leap year or not! is given below:
#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
if (year % 4 == 0) {
if (year % 100 == 0) {
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;
}
Output:
Enter a year: 2020
2020 is a leap year.
Pro-Tips💡
This program prompts the user to enter a year, and then checks whether it is a leap year using the following logic:
- If the year is divisible by 4, it is a leap year, unless…
- If the year is divisible by 100, it is not a leap year, unless…
- If the year is divisible by 400, it is a leap year.
The program then prints whether the year entered is a leap year or not.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.