C program to find that entered year is leap year or not
In this program you will learn how to find out that a year is leap year or not.
In this program you will learn how to find out that a year is leap year or not.
/* Program to find that entered year is leap year or not.
Author: Atnyla Developer */
// C program to check if a given year is leap year or not
#include <stdio.h>
#include <stdbool.h>
bool checkYear(int year)
{
// If a year is multiple of 400, then it is a leap year
if (year%400 == 0)
return true;
// Else If a year is muliplt of 100, then it is not a
// leap year
if (year%100 == 0)
return false;
// Else If a year is muliplt of 4, then it is a leap year
if (year%4 == 0)
return true;
return false;
}
int main()
{
int year;
printf("Enter a year to be check \n");
scanf("%d", &year);
checkYear(year)? printf("Leap Year \n"): printf("Not a Leap Year \n");
return 0;
}
enter any year: 2012
year is a leap year
Press any key to continue . . .
Enter a year to be check
2100
Not a Leap Year
Press any key to continue . . .
A year is leap year if following conditions are satisfied
1) Year is multiple of 400
2) Year is multiple of 4 and not multiple of 100.
Following is pseudo code
if year is divisible by 400 then is_leap_year else if year is divisible by 100 then not_leap_year else if year is divisible by 4 then is_leap_year else not_leap_year
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.