WAP in C to Check Whether a Year is Leap Year or Not Using if else statement?

#include<stdio.h>
#include<conio.h>
int main()
{
int year;
clrscr();
printf(“Enter a year”);
scanf(“%d”, &year);
if( year%400 == 0)
printf(“%d is a leap year.\n”, year);
else if( year%100 == 0)
printf(“%d is not a leap year.\n”, year);
else if( year%4 == 0 )
printf(“%d is a leap year.\n”, year);
else
printf(“%d is not a leap year.\n”, year);
getch();
return(0);
}

Output :-

leapif1leapif2

Explanation :-

A year that has 366 days is called a leap year.A year can be checked whether a year is leap year or not by dividing the year by 4, 100 and 400. If a number is divisible by 4 but not by 100 then, it is a leap year. Also, if a number is divisible by 4, 100 and 400 then it is a leap year. Otherwise the year is not a leap year.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s