The program should ask the user to enter a number as a year. The program then te
ID: 3544435 • Letter: T
Question
The program should ask the user to enter a number as a year. The program then tests whether the input year is a leap year or not. Finally, it displays a message to indicate a leap year or not. To determine if a year is a leap year or not:
A year is leap if it is divisible by 400 (example 1600).
A year is leap if it is divisible by 4 but not divisible by 100 (example 2012).
A year is Not leap if it is divisible 4 and by 100 (example 1700).
A year is Not leap if it is not divisible by 4 (example 2013).
Your program should display an error message when user enters a 0 or negative number.
Example of program run:
Please Enter a year: 2013
Year 2013 is not a leap year
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
int year;
cout <<"Please Enter Year :";
cin>> year;
cout << endl;
if(year%400 ==0 || (year%100 != 0 && year%4 == 0))
cout <<"year "<<year <<" is a leap year" << endl;
else
cout <<"year "<<year <<" is not a leap year" << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.