Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a c++ function that is a recursive version of problem 6: Problem 6: To det

ID: 3793885 • Letter: W

Question

Write a c++ function that is a recursive version of problem 6:

Problem 6:

To determine whether a year is a leap year, you use the following rules 1.if the year is evenly divisible by 4 go to step 2.

Otherwise go to step 5. 2. If the year is evenly divisible by 100, go to step 3. Otherwise go to step 4: 3.If the year is evenly divisible by 400, go to step 4. Otherwise go to step 5: 4.The year is a leap year (which, oddly, means it has an extra day, or 366 days). 5. The year is not a leap year (which means it has 365 days. Now you know how to calculate a leap year. I’m thinking step 3 isn’t going to come in handy for most of us. That said, write a function that calculates all the leap years for the next 400 years and prints them out (starting with 2017, which won’t be printed out).

Explanation / Answer

#include <iostream>

using namespace std;
void isLeapYear(int year, int upto){
if(year == upto){
return;
}
if ((year%4 == 0 && year%100 !=0)|| year%400 == 0){
cout<<year<<" ";
}
isLeapYear(year+1, upto);
}

int main()
{
cout<<"Leap Years: "<<endl;
isLeapYear(2017, 2017+400);
cout<<endl;
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                             

Leap Years:                                                                                                                                                                                                                                                              

2020 2024 2028 2032 2036 2040 2044 2048 2052 2056 2060 2064 2068 2072 2076 2080 2084 2088 2092 2096 2104 2108 2112 2116 2120 2124 2128 2132 2136 2140 2144 2148 2152 2156 2160 2164 2168 2172 2176 2180 2184 2188 2192 2196 2204 2208 2212 2216 2220 2224 2228 2232 2236

2240 2244 2248 2252 2256 2260 2264 2268 2272 2276 2280 2284 2288 2292 2296 2304 2308 2312 2316 2320 2324 2328 2332 2336 2340 2344 2348 2352 2356 2360 2364 2368 2372 2376 2380 2384 2388 2392 2396 2400 2404 2408 2412 2416

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote