How to Check Year is a Leap Year or Not in C:-
In this program we have to find the year is a leap year or not. Generally we assume that year is exactly divisible by 4 is a leap year. But it is not only in this case 1900 is divisible by 4. But it is not a leap so it that case we follows these conditions
- It is exactly divisible by 100
- If it is divisible by 100, then it should also exactly divisible by 4
- And it is divisible by 400
These all conditions are true year is a leap year.
ALGORITHMS:-
Step 1. Initialize variable “year” to find leap year.
Step 2. Take input from User.
Step 3. We use this condition ((year%4==0)&& (year%100!=0)) || (year%400==0)) to check the year is Leap or not.
Step 4. It is true display year is a leap year.
Step 5. It is false display year is not a leap year.
Step 6. Stop.
CODE: -
#include<stdio.h>
int main()
{
int year;
printf("Enter any year: ");
scanf("%d",&year);
if(((year%100!=0)&&(year%4==0))||(year%400==0))
{
printf("year is leap year");
}
else
{
printf("Year is not a leap year");
}
return 0;
}
OUTPUT:-
Comments
Post a Comment