Monday, July 10, 2006

[1/3] Checking for Leap Year using if-else

This program is the first of the three programs that check whether the entered year is a leap year. This program doesn't check whether the number entered is a four digit number.
Just checks whether the number is divisible by four...
Yet another program to demonstrate the use of the Modulus Operator.

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

#include<stdio.h>
main()
{

int year;

printf ("Enter the year to be checked for validity as a Leap Year:");
scanf ("%d", &year);

if (year%4==0)
{
printf ("The year is a Leap Year.\n");

}
else
{
printf("The year is not a Leap Year.\n");

}
}

The file can be found at:

abhishek said...

if any year divided by 4 then it is called leap year but 1900 is also divided by 4, this year is not leap year.why????

xploreraj said...

Leap year conditions:

1. If the year is divisible by 4, its a leap year (not for century).
2012, 2004
2. Every fourth century is a leap year.
2000,2400,400.
not 2100,2200,2300..

yagnik said...

here is a right programmer;

#include

void main()

{
int a,b,Y;
printf("Enter the year:");
scanf("%d",&Y);

if(0==Y%100)

{ a=Y%400;
if(a==0)
printf("Entered year is leap year");
else
printf("Entered year is not leap year");

}

else
{ b=Y%4;
if(b==0)
printf("Entered year is leap year");
else
printf("Entered year is not leap year");
}
}