Program: Check Whether a Year is Leap Year or Not

Explanation: This program accepts a year from the user and checks whether it is a leap year using the if-else statement.


#include <stdio.h>
#include <conio.h>

main()
{
    int year;

    clrscr();

    printf("Enter the Year : ");
    scanf("%d",&year);

    if(year % 4 == 0)
    {
        printf("\nThis is a Leap Year");
    }
    else
    {
        printf("\nThis is Not a Leap Year");
    }

    getch();
}

Output:

Enter the Year : 2024

This is a Leap Year


Practice Exercises

Task 1: Write a C program to accept a year from the user and check whether it is divisible by 100 or not using the if-else statement.

Goal: Learn how to use the modulus (%) operator with the if-else statement.
💡 Hint: If the remainder after dividing the year by 100 is 0, then the year is divisible by 100.
💡 Show Solution

#include <stdio.h>
#include <conio.h>

main()
{
    int year;

    clrscr();

    printf("Enter the Year : ");
    scanf("%d",&year);

    if(year % 100 == 0)
    {
        printf("\nYear is Divisible by 100");
    }
    else
    {
        printf("\nYear is Not Divisible by 100");
    }

    getch();
}

Output
Enter the Year : 2000

Year is Divisible by 100
Explanation: The program accepts a year from the user and checks whether it is divisible by 100 using the modulus (%) operator. If the remainder is 0, it displays "Year is Divisible by 100"; otherwise, it displays "Year is Not Divisible by 100".