Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Python program to check Leap Year|Python language

Leap year program in C++ language|C++ program

Posted on November 18, 2020November 18, 2020

Table of Contents

  • Leap year program in C++ language
    • Leap year program in C++
      • Check whether the given year is leap or not- using if-else
      • Check whether the given year is leap or not- using if-else if-else
      • Check whether the given year is leap or not- using Nested if
      • Check whether the given year is leap or not- using ternary operator
      • Check whether the given year is leap or not- using function

Leap year program in C++ language

In this article, we will discuss the concept of Leap year program in C++ language

In this Program, we are going to learn how to make sure the given year whether leap year or not using different methods in C++ language.

This is done using if-else , if-else if-else, Nested -if,ternary operator and function in C++ language.

Leap year program in C++

Check whether the given year is leap or not- using if-else

In this code, we are going to learn how to make sure the given year whether leap year or not using if-else statements in C++ language

Program 1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int year;

    cout<<"Enter a year for check leap or not\n";
    cin>>year;

   if ((year%400==0)||((year%4==0)&&(year%100!=0))){
     cout<<year<<" is a leap year ";
}
     else{
     cout<<year<<" is not a leap year ";
}
getch();
    return 0;
}

When the above code is executed,it produces the following result

Case 1

Enter a year for check leap or not
2064
2064 is a leap year

Case 2

Enter a year for check leap or not
2082
2082 is not a leap year

 

 

Check whether the given year is leap or not- using if-else if-else

In this code, we are going to learn how to make sure the given year whether leap year or not using if-else if.else statements in Cpp language

Program 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int year;
    cout<<"Enter a year for check leap or not\n";
    cin>>year;
    if(year%400==0){
   cout<<year<<" is a leap year ";
}
else if(year%100==0){
  cout<<year<<" is not a leap year ";
}

   else if(year%4==0){
     cout<<year<<" is a leap year ";
   }
     else{
     cout<<year<<" is not a leap year ";
}
getch();
    return 0;
}

When the above code is executed,it produces the following result

Case 1

Enter a year for check leap or not
2060
2060 is a leap year

Case 2

Enter a year for check leap or not
2090
2090 is not a leap year

 

 

Check whether the given year is leap or not- using Nested if

In this program, we are going to learn how to make sure the given year whether leap year or not using Nested if statements in C++ language

Program 3

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int year;

    cout<<"Enter a year for check leap or not\n";
    cin>>year;

   if(year%4==0){
     if(year%100==0){
           if(year%400==0){
      cout<<year<<" is a leap year ";
        }else
     cout<<year<<" is not a leap year ";
    } else
     cout<<year<<" is a leap year ";
  }else
      cout<<year<<" is not a leap year ";
getch();
    return 0;
}

When the above code is executed,it produces the following result

Case 1

Enter a year for check leap or not
2220
2220 is a leap year

Case 2

Enter a year for check leap or not
2094
2094 is not a leap year

 

Check whether the given year is leap or not- using ternary operator

In this code, we are going to learn how to make sure the given year whether leap year or not using Ternary operator in C++ language

Program 4

 

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int year;
    cout<<"Please Enter year for check leap or not: \n";
   cin>>year;
    (year%4==0 && year%100!=0)? cout<<"The entered year is a leap year":year%400==0?
    cout<<"The entered year is a leap year"
:cout<<"This is not a leap year";
getch();
    return 0;
}

When the above code is executed,it produces the following result

Case 1

Enter a year for check leap or not
2064
The entered year is a leap year

 

Case 2

Enter a year for check leap or not
2070
This is not a leap year

Check whether the given year is leap or not- using function

In this code, we are going to learn how to make sure the given year whether leap year or not using user defined function in Cpp language

Program 5

#include <iostream>
#include <conio.h>
using namespace std;

int leapYear(int);//function prototype
int main()
{
    int year;
    cout<<"Enter the year for check leap\n";
    cin>>year;
    if(leapYear(year))
        cout<<year<<" is a leap year";
    else
        cout<<year<<" is not a leap year";
        getch();
    return 0;
}

int leapYear(int y)
{
    if((y%400==0)||((y%4==0)&&(y%100!=0)))
       return 1;
    else
        return 0;
}

When the above code is executed,it produces the following result

Case 1

Enter a year for check leap or not

2136

2136 is a leap year

Case 2

Enter a year for check leap or not

2500

2500 is not a leap year

 

Suggested post

Operator in C++ language

if statements in C++ language

Nested if statement in C++ language

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes