Answer to Question #3340 in C++ for mukunda
Question #3340
Take a year as input and check whether it is leap year or not?
Expert's answer
#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;
}
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 orderand get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Leave a comment