Write a  C++ Program to Check Leap Year

C++ Program to Check Leap Year

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C++ programming concepts. You can learn C++ language at your own speed and time. One can learn concepts of C++ language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

C++ Program to Check Leap Year
C++ Program to Check Leap Year

Write a  C++ Program to Check Leap Year

PROGRAM:C++ Program to Check Leap Year

/* C++ Program to Check Leap Year */

#include <iostream>
using namespace std;

int main() {

int year;
cout << “Enter a year: “;
cin >> year;

// leap year if perfectly divisible by 400
if (year % 400 == 0) {
cout << year << ” is a leap year.”;
}
// not a leap year if divisible by 100
// but not divisible by 400
else if (year % 100 == 0) {
cout << year << ” is not a leap year.”;
}
// leap year if not divisible by 100
// but divisible by 4
else if (year % 4 == 0) {
cout << year << ” is a leap year.”;
}
// all other years are not leap years
else {
cout << year << ” is not a leap year.”;
}

return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *