C++ Program to Check Whether a Given Year is a Leap Year

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.

  1. /*
  2.  * C++ Program to Check if the Entered Year is a Leap Year
  3.  */
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int year;
  10.  
  11.     cout << "Enter the year in yyyy format : ";
  12.     cin >> year;
  13.     if (year % 4 == 0)
  14.         cout << year << " is a leap year";
  15.     else
  16.         cout << year << " is not a leap year";
  17. }

$ 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.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.