C Leap Year Check Program
A Leap Year Check program determines whether a given year is a leap year or not. A leap year has 366 days instead of the usual 365 days and occurs every four years to help synchronize the calendar year with the astronomical year.
Rules for Identifying a Leap Year:
- A year is a leap year if it is divisible by 4.
- However, if the year is divisible by 100, it is not a leap year unless:
- The year is also divisible by 400, in which case it is a leap year.
Logic of the Program:
- Input a year from the user.
- Check the conditions for leap year:
- If the year is divisible by 4.
- If it is divisible by 100, check if it is also divisible by 400.
- Print whether the year is a leap year or not based on these conditions.
Program:
Here’s a C program to check if a year is a leap year:
Explanation:
Variables:
int year
: Holds the year inputted by the user.
Input:
- The program prompts the user to enter a year.
Leap Year Logic:
- The program checks if the year is divisible by 4 and not divisible by 100, or if it is divisible by 400.
- If either condition is met, the program considers it a leap year.
Output:
- The program prints whether the entered year is a leap year or not based on the evaluation.
Sample Output:
Example 1:
Example 2:
Example 3:
Key Points:
- Divisibility Conditions: The program effectively uses logical operators to combine conditions for determining leap years, ensuring accurate results.
- User Interaction: The program interacts with the user by prompting for input and displaying results clearly.
- Efficiency: The checks are simple and efficient, with only a few modulus operations needed to determine if the year is a leap year.
- Comprehensive Handling: The program correctly handles all cases of leap years as per the Gregorian calendar rules.