This C++ Program which checks if the year entered is a leap year. The program checks whether the entered year is divisible by 4 since leap year repeats itself every four year and if the year is divisible by 4, the year is a leap year.
Here is source code of the C++ program which checks if the year entered is a leap year. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Check if the Entered Year is a Leap Year
*/
#include <iostream>
using namespace std;
int main()
{
int year;
cout << "Enter the year in yyyy format : ";
cin >> year;
if (year % 4 == 0)
cout << year << " is a leap year";
else
cout << year << " is not a leap year";
}
$ g++ main.cpp $ ./a.out Enter the year in yyyy format : 2013 2013 is not a leap year $ ./a.out Enter the year in yyyy format : 2012 2012 is a leap year
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Related Posts:
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Check C++ Books
- Check Computer Science Books
- Practice Programming MCQs