c program to check user value is leap year or not

#include<stdio.h>
int main()
{
    int year;
    
    printf("Enter the year: ");
    scanf("%d",&year);

    /*
    **    The logic is that the year is either divisible by both
    **    100 and 4 , OR its only divisible by 4 not by hundred
    */
    if(year%400 ==0 || (year%100 != 0 && year%4 == 0))
    {
        printf("Year %d is a leap year",year);
    }
    else
    {
        printf("Year %d is not a leap year",year);
    }
    
    getch();
}

Comments

Popular posts from this blog