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:
- WAP in C++ & Python & sort an Array Using Bubble Sort
- Python Program to Find ASCII Value of Character
- C Program to Convert Feet into Inches
- WAP to calculate sum and average of three numbers
- C Program to Extract a Portion of String
- WAP to create a loading bar
- How many Centimeters in a Foot through Python?
- Python Examples
- Rectangle & Pyramids Pattern in C++
- WAP to convert a lowercase alphabet to uppercase or vice-versa using ASCII code
Leave a Comment on this Post