Leap year or not in C language

 WAP that tells whether a given year is a leap year or not.

To determine whether a year is a leap year or not, you can use the following conditions:

  • If the year is evenly divisible by 4 and 400 it is a leap year.
  • However, if the year is evenly divisible by 100, it is not a leap year, unless:


#include<stdio.h>  

#include<conio.h>  

void main() 

{  

   int year;

   clrscr();

   printf("Enter a 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);

   getch();

}  


Output

Enter a year: 1800 

1800 is not a leap year


Enter a year: 2020

2020 is a leap year

Post a Comment

0 Comments