Search This Blog

Find a year is leap year or not | C programming

Find a year is leap year or not 

Problem

Read a integer value, which a natural number. Find the the year is a leap year or not.


Input

The input file contains a integer value.

Output

Print the year is a leap year or not.




 

Solution

First of all we have to know what is a leap year. A common year has 365 days and a leap year has 366 days. Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 were not leap years, but the years 1600 and 2000 were.



#include<stdio.h>

int main()
{
    int year;

    scanf("%d",&year);

    if(year%4 !=0){
        printf("%d is a common year\n",year);
    }

    else if(year%4 == 0){
        if(year%100 ==0){
            if(year%400 == 0){
             printf("%d is a leap year\n",year);
            }
            else{
                printf("%d is a common year\n",year);
            }
        }

        else{
                printf("%d is a leap year\n",year);
            }
    }

    return 0;
}



 

No comments

Powered by Blogger.