Leap Year Program in C

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest in 3 Numbers
Find Grade of student
Find the absolute value
Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

Here we will write the leap year program in C language. We can use if-else, nested if-else, or switch case statement for this problem.

A year is called leap year if the year is divisible by four, except for the years which are divisible by 100 but not divisible by 400. Therefore, the year 2000 was a leap year, but the years 1700, 1800, and 1900 were not.

The complete list of leap years in the first half of the 21st century is 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036, 2040, 2044, and 2048. Prerequisites for leap year program:- If-else statement in C, Programs on if-else in C, Switch case in C programming, Programs on switch case in C

Leap Year Program in C Using if-else statement

#include<stdio.h>
int main()
{
  int year;

  printf("Enter Year: ");
  scanf("%d",&year);

  if(( year%4==0) && ( (year%400==0) || (year%100!=0) ) )
    printf("%d is a leap year.",year);
  else
    printf("%d is not a leap year.",year);

  return 0;
}

Output:-

Enter Year: 2025
2025 is not a leap year.

Enter Year: 2000
2000 is a leap year.

In this program, all conditions are written within the if condition, so it may look likes complicated for you. In the below program, the nested-if statement is used for the same problem. Now, you may understand the logic simply.

Check Leap Year Using nested if-else

#include<stdio.h>
int main()
{
   int year;

   printf("Enter Year:");
   scanf("%d",&year);

   if(year%4==0)
   {
     if(year%100==0)
     {
       if(year%400==0)
         printf("%d is leap year.",year);

       else
         printf("%d is not leap year.",year);
     }

     else
       printf("%d is leap year.",year);
   }

   else
     printf("%d is not leap year.",year);

   return 0;
}

Check Leap Year Using a switch case statement

#include<stdio.h>
int main()
{
   int year, remainder;

   printf("Enter Year: ");
   scanf("%d",&year);

   remainder=((year%4==0)&&((year%400==0)||(year%100!=0)));

   switch(remainder)
   {

   case 1:
     printf("Leap Year.");
     break;

   case 0:
     printf("Not Leap Year.");
     break;

   default:
     printf("Invalid.");
     break;

   }

   return 0;
}

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Similar C program examples

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest among 3 Numbers
Find Grade of student
Find the absolute value
Check Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

Leave a Comment

Your email address will not be published. Required fields are marked *