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

🖥 Program 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

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.

🔥 Practice suggestion

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.