+ 1
anyone can write a program to check whether a year is leap year or not
use if-else statement.đ
2 Answers
0
int year;
cout << "Enter Year \n";
cin >> year;
if (year%4==0)
{
cout << "Leap year";
}
else
{
cout << "Not a leap year";
}
0
Cited in the wiki article of Leap year:
"Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 are not leap years, but the year 2000 is."
So...
int year;
cin >> year;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
cout << "Leap year";
} else {
cout << "Not Leap year";
}