Instructions:
1. You are provided with the isLeapYear() function which is already declared and defined for you.
2. Your task is to ask the user for a year and then call the isLeapYear function to check whether the year is a leap year or not.
Input
1. Year to be checked
Output
If a certain year is a leap year, print "<INSERT_YEAR_HERE> is a leap year"
Otherwise, print "<INSERT_YEAR_HERE> is not a leap year"
Sample Output:
Enter·year:·2020
2020·is·a·leap·year
This is the given code:
#include <iostream>
using namespace std;
int isLeapYear(int);
int main(void) {
// TODO: Write your code here
return 0;
}
int isLeapYear(int n) {
if(
(n % 4 == 0 && n % 100 != 0) ||
(n % 100 == 0 && n % 400 == 0)
) {
return 1;
}
return 0;
}
#include <iostream>
using namespace std;
int isLeapYear(int);
int isLeapYear(int n)
{
if((n % 4 == 0 && n % 100 != 0) || (n % 100 == 0 && n % 400 == 0))
{
return 1;
}
return 0;
}
int main(void)
{
// TODO: Write your code here
int Yr,Flag=1;
while(Flag)
{
cout<<"\n\tEnter a Year: "; cin>>Yr;
if(isLeapYear(Yr)) cout<<"\n\t"<<Yr<<" is a leap year.";
else cout<<"\n\t"<<Yr<<" is not a leap year.";
cout<<"\n\tPress 1 to continue or 0 to QUIT: "; cin>>Flag;
}
return 0;
}
Comments
Leave a comment