A year is said to be a leap year if it is evenly divisible by 4. But, if it is divisible by 100 also, check if it is divisible by 400 or not. If it is divisible 400, then that year is said to be a leap year.
Ex:- 1988(It is a leap year because it is divisible by 4)
1000(It is not a leap year even though it is divisible by 4 because it is divisible by 100 but not by 400)
1200(It is a leap year because it is divisible 4, 100 and 400 all)
#include<stdio.h>
void main()
{
int yr;
clrscr();
printf("Enter a year:");
scanf("%d",&yr);
if(yr%4==0&&yr%100!=0||yr%400==0)
printf("Leap year");
else
printf("Not a leap year");
}
Condition:-
Check if the year is divisible by 4, if divisible by 4 check if it is divisible by 100, if not divisible by 100 print leap year. If divisible by 100, check if it is divisible by 400, if divisible by 400, print leap year else print not a leap year.
0 Comments