Find Leap Year in C++Introduction:A leap year is a year on the Gregorian calendar that has an extra day, February 29, making it 366 days long instead of the typical 365. A leap year is added to the calendar every four years to maintain synchronisation with the Earth's orbit around the Sun. In this article, we'll look at how to use the C++ programming language to check if a particular year is a leap year.
Checking Leap Years in C++:
With these rules in mind, we can proceed to write a C++ program to determine leap years. C++ Program: Explanation:
Let's see how this program works with some examples: Example 1: Suppose we run the program and enter the year 2020. Output 1: Enter a year: 2020 2020 is a leap year. 2020 fits the criteria for being a leap year because it is divisible by 4 and not by 100. Example 2: Now, let's try the program with the year 1900. Output 2: Enter a year: 1900 1900 is not a leap year. In this instance, 1900 is not only divisible by 4, but also by 100. It is not a leap year, though, as it is not divisible by 400. Example 3: Finally, let's test the program with the year 2000. Output 3: Enter a year: 2000 2000 is a leap year. The year 2000 is regarded as a leap year because it may be divided by 4, 100, and 400. Conclusion:In this post, we looked at how to use the C++ programming language to check if a particular year is a leap year. We built a straightforward programme that examines the conditions to identify leap years in accordance with the Gregorian calendar's standards for leap years. In conclusion, knowing how to calculate leap years in C++ is useful for handling dates, planning events, and using other time-related applications. The offered code offers a fundamental framework that may be developed and altered to meet your unique requirements. Next TopicHow to Access Vector Elements in C++ |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India