/* Program to find that entered year is leap year or not.
Author: Atnyla Developer */
// One line C program to check if a given
// year is leap year or not
#include <stdio.h>
#include <stdbool.h>
bool checkYear(int year)
{
// Return true if year is a multiple pf 4 and
// not multiple of 100.
// OR year is multiple of 400.
return (((year%4==0) && (year%100!=0)) ||
(year%400==0));
}
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;
}
<b>Output 1 </b>
Enter a year to be check
2100
Not a Leap Year
Press any key to continue . . .
<b>Output 2 </b>
Enter a year to be check
2012
Leap Year
Press any key to continue . . .
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.