Leap Year in C++
Q. Write a C++ program to check whether the given year is leap year or not?
#include <iostream>
using namespace std;
int main()
{
int yr;
cout << "Enter a Year: ";
cin >> yr;
if ( yr % 400 == 0)
cout << yr << " is a leap year.";
else if ( yr % 100 == 0)
cout << yr << " is not a leap year.";
else if ( yr % 4 == 0)
cout << yr << " is a leap year.";
else
cout << yr << " is not a leap year.";
return 0;
}
Q. Write an algorithm to check whether the given year is leap year or not?
1. Start
2. Prompt the user to enter a year.
3. Read the input year into variable `yr`.
4. Check if `yr` is divisible by 400:
- If yes, print "`yr` is a leap year."
5. Otherwise, check if `yr` is divisible by 100:
- If yes, print "`yr` is not a leap year."
6. Otherwise, check if `yr` is divisible by 4:
- If yes, print "`yr` is a leap year."
7. Else,
- Print "`yr` is not a leap year."
8. End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com