In: Computer Science
Write C++ code according to this prompt:
void print10LeapYears() gets a Gregorian year and prints the first 10 leap years after (but not including) the year input. Nothing is printed if the year is invalid. The first Gregorian year was 1752. The program should prompt the user with "Enter year -->" and each leap year should be preceded by "Leap year is" ...
void print10LeapYears() {
// your code here
return;
}
#include<iostream>
using namespace std;
void print10LeapYears(int year)//function to print 10 leap years
after given year
{
int count=0;//stores count of leap years
while(count!=10)//whenever the count is 10 then loop
will exit
{
//program to find given year is
leap year or not.if it is leap year then count will increment
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
{
count++;
cout<<year<<endl;
}
}
else
{
count++;
cout<<year<<endl;
}
}
year++;//for eeach iteration year will be
incremented
}
}
int main()
{
int year;
cout<<"Enter year: ";
cin>>year;
cout<<"10 leap years are :"<<endl;
print10LeapYears(year+1);//here adding 1 means no need
to check given year(no including input year)
return 0;
}