Saturday, January 30, 2010

CHAP 2[C]c Checking for leap year

Any year is input through the keyboard. Write a program to determine whether the year is a leap year or not.
(Hint: Use the % (modulus) operator)


void main()
{
int year;
printf("\nInput the year");
scanf("%d",&year);

if((year%4==0&&year%100!=0)||year%400==0)

printf("\nThe Year is a leap year");

else
printf("\nThe Year is not a leap year");
}

4 comments:

  1. can you explain logic of this

    ReplyDelete
  2. @prashant
    duration of a solar year is slightly less than 365.25 days. Years that are evenly divisible by 100 are not leap years, unless they are also evenly divisible by 400, in which case they are leap years
    1600 and 2000 were leap years, but 1700, 1800 and 1900 were not.

    ReplyDelete
  3. always try easy logic
    #include
    int main ()
    {
    int year;
    cout<<"Enter the year";
    cin>>year;
    if (year%4==0)
    cout<<"Leap Year";
    else
    cout<<"Non Leap Year";
    system("pause");
    return 0;
    }

    ReplyDelete