Programs

C++ Program to Check Leap Year

C++ Program to Check Leap Year

In the Gregorian calendar, a year is considered a leap year if it meets one of the following conditions:

  1. It is divisible by 4.
  2. It is not divisible by 100, unless it is also divisible by 400.

Here’s a Turbo C++ program to check if a given year is a leap year or not:

#include <iostream.h>
#include <conio.h>

void main() {
    clrscr();  // Clear the screen (specific to Turbo C++)

    int year;

    cout << "Enter a year: ";
    cin >> year;

    // Check if the year is a leap year
    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
        cout << year << " is a leap year." << endl;
    } else {
        cout << year << " is not a leap year." << endl;
    }

    getch();  // Wait for user input (specific to Turbo C++)
}

To compile and run this program in Turbo C++:

  1. Open Turbo C++.
  2. Create a new file and copy-paste the above code into it.
  3. Save the file.
  4. Compile the code (usually by pressing Alt + F9).
  5. Run the program (usually by pressing Ctrl + F9).

After entering a year, the program will display whether it is a leap year or not based on the given conditions.