C program to find leap year

If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

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

//Accepting year
 printf("Enter year\n");
 scanf("%d",&year);

//Checking leap year or not
 if(year%100==0)
 {
  if(year%400==0)
   printf("\n Leap Year");
  else
   printf("\n Not Leap Year");
 }
 else
 {
  if(year%4==0)
   printf("\nLeap Year");
  else
   printf("\nNot Leap Year");
  }
}

OUTPUT:

Enter year
2017

Not Leap Year
-------------------------------------
Enter year
2004

Leap Year

 

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.