Determine if a year is a leap year. - C Statement

C examples for Statement:if

Description

Determine if a year is a leap year.

Demo Code

#include <stdio.h>

int main (void)
{
    int year, rem_4, rem_100, rem_400;

    printf ("Enter the year to be tested: ");
    scanf ("%i", &year);

    rem_4 = year % 4;/*from w ww  .jav  a  2s . c om*/
    rem_100 = year % 100;
    rem_400 = year % 400;

    if ( (rem_4 == 0 && rem_100 != 0 ) || rem_400 == 0)
        printf ("It's a leap year.\n");
    else
        printf ("Nope, it's not a leap year\n");

    return 0;
}

Result


Related Tutorials