Home / Programs / One line C program to check if a given year is leap year or not
Programming Example

One line C program to check if a given year is leap year or not

👁 9,623 Views
💻 Practical Program
📘 Step by Step Learning
One line C program to check if a given year is leap year or no

Program Code

/* 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;
}

Output

<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 . . .

Explanation

One line C program to check if a given year is leap year or not

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.