Answer to Question #3340 in C++ for mukunda

Question #3340
Take a year as input and check whether it is leap year or not?
1
Expert's answer
2011-07-15T14:26:47-0400
#include <iostream>
using namespace std;

int main()
{
int year;
cout << "Please enter a year: ";
cin >> year;

bool leap = false;
if (year % 400 == 0) leap = true;
else if (year % 100 == 0) leap = false;
else if (year % 4 == 0) leap = true;

if (leap) cout << "This year is leap year." << endl;
else cout << "This year is not leap year." << endl;

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS