Write a program in C++ and python to check whether the year is a leap year or not

Posted in

Write a program in C++ and python to check whether the year is a leap year or not

Vinay Khatri
Last updated on August 9, 2022

    In the program we will ask the user to enter a year and display whether the year is a leap year or not, there are some conditions to be a leap year.

    Leap Year Program in C++

    #include<iostream.h>
    #include<conio.h>
    #include<stdio.h>
    #include<math.h>
    void main()
    {
    clrscr();
    int y;
    cout<<"Enter any year: ";
    cin>>y;
    if (y%4==0){
           if(y%100==0)
    
             {if(y%400==0)
                 cout<<"It is a leap year";
               else
                cout<<"It is not a leap year";}
              else
                cout<<"It is a leap year";
              }
    else
      cout<<"It is not a leap year";
    getch();
    
    }

    Output:

    Enter any year: 5000
    It is a leap year

    Leap Year Program in Python

    y= int(input("Enter any year: "))
    if y%4==0:
        if y%100:
            if y%400==0:
                print("It is a leap year")
            else:
                print("It is not a leap year")
        else:
            print("It is a leap year")
    else:
        print("It is not a leap year")

    Output:

    Enter any year: 2019
    It is not a leap year

    People are also reading:

    Leave a Comment on this Post

    0 Comments