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

5.29) (In C++) (Display leap years) Write a program that displays all the leap y

ID: 3733450 • Letter: 5

Question

5.29) (In C++) (Display leap years) Write a program that displays all the leap years, 10 per line, in the period between two positive integer year periods entered by the user, separated by exactly one space. (In c++) The example answer:

Enter·a·positive·start·year:1666

Enter·a·positive·end·year·greater·then·start·year:1999

1668·1672·1676·1680·1684·1688·1692·1696·1704·1708·

1712·1716·1720·1724·1728·1732·1736·1740·1744·1748·

1752·1756·1760·1764·1768·1772·1776·1780·1784·1788·

1792·1796·1804·1808·1812·1816·1820·1824·1828·1832·

1836·1840·1844·1848·1852·1856·1860·1864·1868·1872·

1876·1880·1884·1888·1892·1896·1904·1908·1912·1916·

1920·1924·1928·1932·1936·1940·1944·1948·1952·1956·

1960·1964·1968·1972·1976·1980·1984·1988·1992·1996·

Explanation / Answer

#include <bits/stdc++.h>

using namespace std;

bool check_leap_year(int year)

{

if (year % 400 == 0)

return true;

if (year % 100 == 0)

return false;

if (year % 4 == 0)

return true;

return false;

}

int main()

{

int start, end;

int count = 0;

vector<int>leap_years;

cout<<"Enter positive start of the year"<<endl;

cin>>start;

cout<<"Enter the ending year"<<endl;

cin>>end;

for(int i = start; i<=end; i++)

{

if(check_leap_year(i))

{

count++;

leap_years.push_back(i);

}

}

cout<<"count "<<count<<endl;

int lines = count/10;

int print = 0;

for(int i = 1; i<=lines; i++)

{

for(int j=0;j<10;j++)

{

cout<<leap_years[print]<<" ";

print++;

}

cout<<endl;

}

while(print<count)

{

cout<<leap_years[print]<<" ";

print++;

}

cout<<endl;

}

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