Showing posts with label To check if it is Leap Year. Show all posts
Showing posts with label To check if it is Leap Year. Show all posts

To check if it is Leap Year with C

#include <stdio.h>
void main(void)
{
    int year;
    printf("Enter a year to check if it is Leap Year\n");
    scanf("%d",&year);
    if(year%400==0) /* Why  mod 400 */
        printf("%d is a Leap Year\n",year);
    else if(year%100==0) /*  Why  mod 100  */
        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);

}