by declaring all variables at the beginning of the program. #include <iostream>
ID: 3551812 • Letter: B
Question
by declaring all variables at the beginning of the program.
#include <iostream>
using name space std;
int main()
{
cout <<"Enter a year :";
int year;
cin >> year;
//Check if the year is a leap year
bool isLeapYear=
(year%4==0 && year %100 !=0) || (year %400 ==0);
//Display the result
if (isLeapYear)
cout << year << "is a leap year" << endl;
else
cout <<year << "is a not leap year "<< endl;
return 0;
}
*Enter a year :2008
2008 is a leap year
Enter a year : 1900
1900 is not a leap year
Enter a year: 2002
2002 is not a leap year
Explanation / Answer
#include <iostream>
using name space std;
int main()
{
int year;
bool isLeapYear;
cout <<"Enter a year :";
cin >> year;
//Check if the year is a leap year
isLeapYear=
(year%4==0 && year %100 !=0) || (year %400 ==0);
//Display the result
if (isLeapYear)
cout << year << "is a leap year" << endl;
else
cout <<year << "is a not leap year "<< endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.