Advertisement
fueanta

Leap YearS in a range.

Nov 4th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int first, last, count = 0;
  7.     cout << "From : "; cin >> first;
  8.     cout << "To : "; cin >> last;
  9.     for (int i = first; i <= last; i++) {
  10.         if (i % 400 == 0) {
  11.             cout << i << " is a Leap Year." << endl;
  12.             count++;
  13.         }
  14.         else if (i % 4 == 0 && i % 100 != 0) {
  15.             cout << i << " is a Leap Year." << endl;
  16.             count++;
  17.         }
  18.         else cout << i << " is not a Leap Year." << endl;
  19.     }
  20.     cout << "\nTotal leap years in this range: " << count << endl;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement