In this article, we will discuss the concept of C++ program for check whether given year is leap using function
In this post, we are going to learn how to write a program to check the given year is leap or not using function in C++ programming language
A normal year contains 365 days but a leap year contains 366 days
leap year is occurring once every four years, which has 366 days including 29 February as an intercalary day. it is called leap year
Century year
The century year is ending with 00
Ex 2000, 2100, 2200
a century year may be a leap year but it is not compulsory
How to find the leap year
if The given year is perfectly divisible by 4 , it is a leap year(except century year)
only if is perfectly divisible by 400, the century year is a leap year,
a century year should be divisible by 4 and 100 both
a non century year should be divisible only by 4
Here, The program allows the user to enter the year and then it will check the year is a leap year or not, using function in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int leap_Year(int);//function prototype int main() { int year;//variable declaration cout<<"Enter the year for check leap year\n"; //Ask input from the user cin>>year; //store the input value in the year variable if(leap_Year(year))//function call cout<<year<<" is a leap year"; else cout<<year<<" is not a leap year"; getch(); return 0; } int leap_Year(int y) { if((y%400==0)||((y%4==0)&&(y%100!=0))) //Leap year if perfectly divisible by 400 //Leap year if perfectly divisible by 4 //not a leap year if not divisible by 100 return 1; else return 0; }
When the above code is executed , it produces the following result
Case 1
Enter the year for check leap year 2032 2032 is a leap year
Case 2
Enter the year for check leap year 2038 2038 is not a leap year
Suggested post
Nested if statements in C++ language
Similar post
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…