C++ language Write a program determines if a number represents a leap year or no
ID: 3585274 • Letter: C
Question
C++ language
Write a program determines if a number represents a leap year or not. If the number is less than 1 then the program displays the phrase "not leap year". If 400 divides the number without remainder the program displays the phrase "leap year". If 4 divides the number without remainder and 100 divides the number with remainder then the program displays the phrase "leap year". If these conditions are false then the program displays the phrase "not leap year". If possible write only 1 multi-way if statement with compound conditions to solve the problem.
Test your if statement or if statements with these numbers: -1492, 1776, 1865, 1900, 2000, and 2014
-1492 is not a leap year.
1776 is a leap year
1865 is not a leap year.
1900 is not a leap year
2000 is a leap year
2014 is not a leap year
Explanation / Answer
#include <iostream>
using namespace std;
bool isLeapYear(int year){
if ((year%4 == 0 && year%100 !=0)|| year%400 == 0){
return true;
}
return false;
}
int main()
{
int year;
cout<<"Enter the year: "<<endl;
cin >> year;
if(year < 1 || !isLeapYear(year) ) {
cout<<year<<" is not a leap year"<<endl;
}
else {
cout<<year<<" is a leap year"<<endl;
}
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.