Use C++ only.
1) Write a full program that will take a list of years and it will check if they are leap years. As soon as the program finds the first leap year from the list, the program terminates. The program also terminates when it reads a -1.
Please make use of the do . . . while loop structure and the break statement.
Example of sample runs:
Enter a list of years:
1841 1854 1862 1875 1879 1892 1896 1903 -1
Leap Year found: 1892
Program terminated.
(OR)
Enter a list of years:
1841 1854 1862 1875 1879 1895 1898 1903 -1
No Leap Years found!
Program terminated.
#include <iostream> using namespace std; int main() { int year; cout << "Enter a list of years:" << endl; do { cin >> year; if (year == 0) { cout << "\nNo Leap Years found!" << endl; break; } if ((year % 400 == 0 || year % 100 != 0) && (year % 4 == 0)) { cout << "\nLeap year found: " << year << endl; break; } } while (true); cout << "Program terminated." << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.