Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

leap year c++

#include <iostream>
using namespace std;

int main() {

  int year;

  cout << "Enter a year: ";
  cin >> year;

  // if year is divisible by 4 AND not divisible by 100
  // OR if year is divisible by 400
  // then it is a leap year
  if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
    cout << year << " is a leap year.";
  }
  else {
    cout << year << " is not a leap year.";
  }

  return 0;
}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #leap #year
ADD COMMENT
Topic
Name
8+7 =