C program to check leap year using conditional operator

C program to check leap year using Conditional operator


In this program, you'll learn C Program to check if the given year is a leap year or not. This is checked using if-else statement.


A leap year is exactly divisible by 4 except for century years (years ending with 00). The century year is a leap year only if it is perfectly divisible by 400.

Since 1900 is divisible by 4 and is also a century year (ending with 00), it has been divisible by 400 for a leap year. Since it's not divisible by 400, 1900 is not a leap year.

#include<stdio.h>
int main()
{ 
 int year;
  printf("\n Enter a year:");
   scanf("%d",&year);
       if(year%100==0)
        {
          if(year%400==0)
             { 
               printf("%d is a leap year",year);
              }
          else
             {
               printf("%d is not a leap year",year);
             }
        }
       else
        { 
          if(year%4==0)
             {
               printf("%d is a leap year",year);
             }
          else
             {
               printf("%d is not a leap  year",year);
             }
        }
 return 0;
}
For example, if the user enters 1900 then the output will be:
Enter a year:1900
1900 is not a leap year



NOTE: You have any problem in the above c program to check if the given year is a leap year or not. This is checked using if-else statement and does not hesitate and write your problem in the comment box. I will support your problem.

Share this

0 Comment to "C program to check leap year using conditional operator"

Post a Comment