Write c++ code that
(1) Please enter the value of a year through the keyboard.
(2) Please program to determine whether the entered year is a leap year.
(3) The conditions for a leap year are: divisible by 4 but not divisible by 100; or divisible by 400.
(4)run test the code in main
#include <iostream>
using namespace std;
bool isLeapYear(int year){
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0){
return true;
}
}
else{
return true;
}
}
return false;
}
int main() {
int year;
cout << "Enter a year: ";
cin >> year;
if(isLeapYear(year)){
cout << year << " is a leap year.";
}else{
cout << year << " is NOT a leap year.";
}
cin >> year;
return 0;
}
Comments
Leave a comment