Friday, October 30, 2009

Checking for leap year

Any year is entered through the keyboard. Write a function to determine whether the year is a leap year or not.

void main()
{
int y;
printf("\nInput the year to check if its a leap year");
scanf("%d",&y);
leap(y);
}

leap(int year)
{
if((year%4==0&&year%100!=0)||year%400==0)
printf("\nIt is a leap year");

else
printf("\nIts not a leap year");
}

No comments:

Post a Comment