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.

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *