A Program to Check a Leap Year

In this example, we are giving a program which is useful to check whether an year given by the user is a leap year or not.


Program to check an year is a leap year or not:

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int year;
  6. cout << "Enter a year: ";
  7. cin >> year;
  8. if(year%4 == 0)
  9. {
  10. if( year%100 == 0)
  11. {
  12. // year is divisible by 400 is a leap year
  13. if ( year%400 == 0)
  14. cout << d << "is a leap year.";
  15. else
  16. cout << d << "is not a leap year.";
  17. }
  18. else
  19. cout << d << "is a leap year.";
  20. }
  21. else
  22. cout << d << "is not a leap year.";
  23. return 0;
  24. }

Output:

Enter an year: 1975
1975 is not a leap year.