Sunday 20 June 2010

WAP to find whether a given year is leap or not?

WAP to find whether a given year is leap or not?

To check whether a year is a leap year or not, you need to check the following 3

conditions:
1. Any year that is divisible by 400 is definitely a leap year.
2. If it is not divisible by 400, then check if it is divisible by 100, if so, then it is

NOT a leap year (even if it is divisible by 4), and
3. If the above two conditions are not satisfied we check for divisibility by 4, it it is

divisible by 4 it is a leap year.

For example,
(we know that 2000 is a leap year)
if year = 2400, it is leap year,(Condition 1 satisfied)
but if year = 2200, is NOT a leap year, (Cond. 2 satisfied),
and if year = 2020, is a leap year, (Cond. 3 satisfied).

You can use simple if else statements to write the program.
You can read Leap Years or Leap year for better understanding of why every 400th year is

taken as a leap year and not every 100th.

#include<stdio.h>
#include<conio.h>
void main()
{
 int year;
 clrscr();
 printf("enter any year\n");
 scanf("%d",&year);
 if(year%4==0 &&year%100!=0||year%400==0)
 printf("Leap year");
 else
 printf("not a leap year");
 getch();
}

Program


No comments:

Post a Comment