C Program to check Leap Year | Check whether the given year is leap year or not
By using following logic you can check whether a given year is leap or not :
Leap Year:
If a year is divisible by 4, 100 and 400 then it is a leap year.
If a year is divisible by 4 but not divisible by 100 then it is a leap year
Not a Leap Year:
If a year is not divisible by 4 then it is not a leap year
If a year is divisible by 4 and 100 but not divisible by 400 then it is not a leap year
Program to check Leap Year
Program 1
Run Code- If you want run this code copy this code, paste here and run.
#include <stdio.h>
int main()
{
    int y;
    printf("Enter year: ");        //enter year
    scanf("%d",&y);
    if(y % 4 == 0)                 //Check whether the year is divisible by 4 or not
    {
        if( y % 100 == 0)          //Check whether the year is divisible by 100 or not
        {
            if ( y % 400 == 0)     //Check whether the year is divisible by 400 or not
                printf("%d is a Leap Year", y);
            else
                printf("%d is not a Leap Year", y);
        }
        else
            printf("%d is a Leap Year", y );
    }
    else
        printf("%d is not a Leap Year", y);
    return 0;
}
Program 2
#include <stdio.h>
int main()
{
  int year;
  printf("\n Please Enter any year you wish \n "); //enter year
  scanf(" %d ", &year);
  //check leap year condition
  if (( year%400 == 0)|| (( year%4 == 0 ) &&( year%100 != 0))) 
      printf("\n %d is a Leap Year. \n", year);
  else
      printf("\n %d is not the Leap Year. \n", year);
   return 0;
}
Output:
Enter year: 2000
2000 is a leap year
Enter year: 1996
1996 is a leap year
Enter year: 2003
2003 is not a leap year


 
 
 
No comments: