The Program in C that receives any year from the keyboard and uses a function to determine whether the year is a leap year or not is given below:
#include <stdio.h>
int isLeapYear(int year) {
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
return 1;
} else {
return 0;
}
} else {
return 1;
}
} else {
return 0;
}
}
int main() {
int year;
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;
}
Output:
Enter a year: 2020
2020 is a leap year
Pro-Tips💡
In this program, the isLeapYear()
function takes an integer as an argument and uses a set of if-else statements to check if the year is a leap year or not.
A leap year is a year that is divisible by 4 except for end-of-century years, which must be divisible by 400.
The program prompts the user to enter a year, then pass the year to the isLeapYear()
function.
The function returns 1 if the year is a leap year and 0 otherwise.
The program then prints a message indicating whether the year 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.