Leap year program in C using if else

Leap year program in C using if else.

before creating program it is important to know what is leap year? Generally, a year has 365 days, but a leap year has 366 days which comes after every 4 year. following are the points related to leap year.

1. A leap year is year. which is different from another year because it has one extra day in the month of February.

2. A leap year comes once in a four year. in which February month has 29 days instead of 28 days.  

3. Some example of leap year are 2004, 2008, 2012 and 2016.

 

Below condition are apply to check following year is leap or not.

1. Year must be divisible by 4.

2. Year is divisible by 400 and not divisible by 100.

 

By putting these condition in your C program you can easily find the year is leap or not leap. These condition can be put with help of if-else or with && (and) and ||(or).

Below are the C program to find whether the year is leap or not

 

Input:-

#include<stdio.h>

#include<conio.h>

void main()

{

int year;

clrscr();

printf(“enter the year:”);

scanf(“%d”,&year);

int temp=year/100;

if(year%100==0)

{

if(temp%4==0)

{

printf(“%d is leap year.”, year);

}

else

{

printf(“%d is ordinary year.”, year);

}

}

else

{

if(year%4==0)

{

printf(” %d is leap year.”, year);

}

else

{

printf(“%d is ordinary year.”, year);

}

}

getch();

}

Output:-

Leap year program in C using if else
Leap year program in C using if else

 

 

1 thought on “Leap year program in C using if else”

Comments are closed.