Leap Year in C


Q. Write a C program to check whether the given year is leap year or not?

#include 
#include 
 
void main()
{
    int yr;
    clrscr();
    printf("Enter a Year :");
    scanf("%d", &yr);
    if ( yr % 400 == 0) 
        printf("%d is a leap year.", yr);
    else if ( yr % 100 == 0) 
        printf("%d is not a leap year.", yr);
    else if ( yr % 4 == 0) 
        printf("%d is a leap year.", yr);
    else
        printf("%d is not a leap year.", yr); 
    getch();
}

Q. Write an algorithm to check whether the given year is leap year or not?

1. Start
2. Prompt the user to Enter a Year and read the input into the variable `yr`.
3. If `yr` is divisible by 400 (i.e., `yr % 400 == 0`), then
- Print "`yr` is a leap year."
4. Else if `yr` is divisible by 100 (i.e., `yr % 100 == 0`), then
- Print "`yr` is not a leap year."
5. Else if `yr` is divisible by 4 (i.e., `yr % 4 == 0`), then
- Print "`yr` is a leap year."
6. Else
- Print "`yr` is not a leap year."
7. End



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.