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
using namespace std;
cout << "Enter the year in yyyy format : ";
cin >> year;
if (year % 4 == 0)
cout << year << " is a leap year";
cout << year << " is not a leap year";
$ g++ main.cpp
Enter the year in yyyy format : 2013
2013 is not a leap year
Enter the year in yyyy format : 2012
2012 is a leap year
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
If you wish to look at all C++ Programming examples, go to C++ Programs
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1,
- Chapterwise Mock Tests: Chapter 1,
, 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
& technical discussions at Telegram SanfoundryClasses