Contact Learn C
Copy

Program 14:To find if the given year is leap year or not

Program 14:
#include<stdio.h>
main()
{
  int year;
  printf("Enter the year you want to check\n");
  scanf("%d",&year);
  if(year%400==0)
  {
    printf("%d is leap year\n",year);
  }
  else if(year%100==0)
  {
    printf("%d is not a leap year\n",year);
  }
  else if(year%4==0)
  {
    printf("%d is a leap year\n",year);
  }
  else
  {
    printf("%d is not a leap year\n",year);
  }
 }
Explanation:
  1. Initialization of variable 'year' for taking user input.
  2. Then prompting user to give the year of his interest.
  3. Now we check whether the year is divisible by 400 or 100 or 4
  4. If the variable is divisible by
    • 400 then it is leap year(ex: 2000,2400)
    • 100 then it is not a leap year.(ex: 2100 which is divisible by 4 but not with 400)
    • 4 then it is leap year.
  5. Then printing the corresponding printf.
Output:
Find if the given year is leap year or not
Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide