C Program to Check Year is a Leap Year or Not

Leap year or not in C programming (1)

Year is a Leap Year or Not

In this program we have to find the year is a leap year or not. Generally  we assume that year is exactly divisible by 4 is a leap year. But it is not only in this case 1900 is divisible by 4. But it  is not a leap so it that case we follows these conditions   

  • It is exactly divisible by 100
  • If it is divisible by 100, then it should also exactly divisible by 4
  • And it is divisible by 400  

These all conditions are true year is a leap year.

Working

  • Step 1. Initialize variable “year” to find leap year.
  • Step 2. Take input from User.
  • Step 3. We use this condition ((year%4==0)&&(year%100!=0)) || (year%400==0)) to check the year is Leap or not.
  • Step 4. It is true display year is a leap year.
  • Step 5. It is false display year is not a leap year.
  • Step 6. Stop.

C Code


    #include<stdio.h>
    int main()
    {
        //initialization of Year
        int year;

    //to take user input
    printf(“Enter Year for find leap year or not : “);
    scanf(“%d”,&year);

    //we use this statement for check leap year
    if(((year%4==0)&&(year%100!=0)) || (year%400==0))
    printf(“%d is a Leap Year”,year);

    //not leap year
    else
    printf(“%d is not a Leap Year”,year);
    return 0;

    }
    Output

    Enter Year for find leap year or not : 2012
    2012 is a leap Year

    Enter Year for find leap year or not : 1900
    1900 is not a leap Year