MALIKA KAROUM

MALIKA KAROUM
  • Home
  • Inleiding
  • Blog
  • video’s
  • Dubai UAE
  • Promotie
  • Marketing
    • Malika Karoum Strategie Modules
    • Malika Karoum Online Marketing
    • Malika Karoum Business Service
    • Malika Karoum Platform
    • Malika Karoum Marketing Platform
    • Online business marketing
  • Luxury
    • The Indulgence Business site
    • The Luxury Web site
    • The Ultimate Indulgence
    • The Indulgence Site
    • The Ultimate Luxury Information site
    • Online luxury
  • Malika Karoum
    • Malika Karoum LinkedIn
    • Malika Karoum Facebook
    • Malika Karoum Instagram
    • Malika Karoum Business News
    • Malika Karoum Promotion
      • Worth for free now
      • Work from Home 2020
      • Gadgets
      • All about Windows
      • about Whatsapp
      • Whats the
      • About websites
      • New Ways
      • New Way of Watching
      • Virtual
      • Website
      • All about Video
      • How to Use
      • YouTube Info
      • All about Twitter
      • The Best of
      • About Apps
      • Google News
      • For Free
      • About This
      • Need More
      • Why should you
      • Iphone news
      • Interesting News
      • About Amazone
      • Some tips
      • About Netflix
      • All about Music
      • About Facebook
    • Adverteren grote fraude
    • Menu POS
    • Malika Karoum Evenementen
  • Malika Security
  • Home
  • Malika Karoum Global News
  • How to Check if a Year Is a Leap Year in Multiple Languages
December 8, 2023

How to Check if a Year Is a Leap Year in Multiple Languages

How to Check if a Year Is a Leap Year in Multiple Languages

by Malika Karoum / Tuesday, 27 July 2021 / Published in Malika Karoum Global News

A leap year is a year that has 366 days. An additional day is added to the leap year to keep the calendar year synchronized with the astronomical year. You can check if a given year is a leap year or not using mathematics and programming.

In this article, you’ll learn how to check whether the given year is a leap year or not using C++, Python, JavaScript, and C.

Problem Statement

You’re given a year. You need to check whether the given year is a leap year or not.

Example 1: Let year = 2021.

2021 is not a leap year.

Thus, the output is “2021 is not a leap year”.

Example 2: Let year = 1980.

1980 is a leap year.

Thus, the output is “1980 is a leap year”.

Condition for a Year to Be a Leap Year

A year is a leap year if any or both of the following conditions are satisfied:

  1. The year is a multiple of 400.
  2. The year is a multiple of 4 and not a multiple of 100.

C++ Program to Check Whether a Year Is a Leap Year or Not

Below is the C++ program to check whether a given year is a leap year or not:

// C++ program to check if a given year is a leap year or not
#include <iostream>
using namespace std;
bool isLeapYear(int y)
{
// If a year is a multiple of 4 and not a multiple of 100 or a multiple of 400,
// then the year is a leap year
// Multiple of 4 and (Not a multiple of 100 or Multiple of 400) => A Leap year
return (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0));
}
int main()
{
int year1 = 2021;
cout << "Year: " << year1 << endl;
if(isLeapYear(year1))
{
cout << year1 << " is a leap year" << endl;
}
else
{
cout << year1 << " is not a leap year" << endl;
}
int year2 = 2012;
cout << "Year: " << year2 << endl;
if(isLeapYear(year2))
{
cout << year2 << " is a leap year" << endl;
}
else
{
cout << year2 << " is not a leap year" << endl;
}
int year3 = 1980;
cout << "Year: " << year3 << endl;
if(isLeapYear(year3))
{
cout << year3 << " is a leap year" << endl;
}
else
{
cout << year3 << " is not a leap year" << endl;
}
int year4 = 1990;
cout << "Year: " << year4 << endl;
if(isLeapYear(year4))
{
cout << year4 << " is a leap year" << endl;
}
else
{
cout << year4 << " is not a leap year" << endl;
}
int year5 = 1600;
cout << "Year: " << year5 << endl;
if(isLeapYear(year5))
{
cout << year5 << " is a leap year" << endl;
}
else
{
cout << year5 << " is not a leap year" << endl;
}
return 0;
}

Output:

Year: 2021
2021 is not a leap year
Year: 2012
2012 is a leap year
Year: 1980
1980 is a leap year
Year: 1990
1990 is not a leap year
Year: 1600
1600 is a leap year

Related: What Is a Fibonacci Sequence and How Do You Print One in Python, C++, and JavaScript?

Python Program to Check Whether a Year Is a Leap Year or Not

Below is the Python program to check whether a given year is a leap year or not:

# Python program to check if a given year is a leap year or not
def isLeapYear(y):
# If a year is a multiple of 4 and not a multiple of 100 or a multiple of 400,
# then the year is a leap year
# Multiple of 4 and (Not a multiple of 100 or Multiple of 400) => A Leap year
return (((y % 4 == 0) and (y % 100 != 0)) or (y % 400 == 0))

year1 = 2021
print("Year: ", year1)
if isLeapYear(year1):
print(year1, "is a leap year")
else:
print(year1, "is not a leap year")
year2 = 2012
print("Year: ", year2)
if isLeapYear(year2):
print(year2, "is a leap year")
else:
print(year2, "is not a leap year")
year3 = 1980
print("Year: ", year3)
if isLeapYear(year3):
print(year3, "is a leap year")
else:
print(year3, "is not a leap year")
year4 = 1990
print("Year: ", year4)
if isLeapYear(year4):
print(year4, "is a leap year")
else:
print(year4, "is not a leap year")
year5 = 1600
print("Year: ", year5)
if isLeapYear(year5):
print(year5, "is a leap year")
else:
print(year5, "is not a leap year")

Related: How to Print “Hello, World!” in the Most Popular Programming Languages

JavaScript Program to Check Whether a Year Is a Leap Year or Not

Below is the JavaScript program to check whether a given year is a leap year or not:

// JavaScript program to check if a given year is a leap year or not
function isLeapYear(y) {
// If a year is a multiple of 4 and not a multiple of 100 or a multiple of 400,
// then the year is a leap year
// Multiple of 4 and (Not a multiple of 100 or Multiple of 400) => A Leap year
return (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0));
}

var year1 = 2021;
document.write("Year: " + year1 + "<br>");
if(isLeapYear(year1)) {
document.write(year1 + " is a leap year" + "<br>");
} else {
document.write(year1 + " is not a leap year" + "<br>");
}
var year2 = 2012;
document.write("Year: " + year2 + "<br>");
if(isLeapYear(year2)) {
document.write(year2 + " is a leap year" + "<br>");
} else {
document.write(year2 + " is not a leap year" + "<br>");
}
var year3 = 1980;
document.write("Year: " + year3 + "<br>");
if(isLeapYear(year3)) {
document.write(year3 + " is a leap year" + "<br>");
} else {
document.write(year3 + " is not a leap year" + "<br>");
}
var year4 = 1990;
document.write("Year: " + year4 + "<br>");
if(isLeapYear(year4)) {
document.write(year4 + " is a leap year" + "<br>");
} else {
document.write(year4 + " is not a leap year" + "<br>");
}
var year5 = 1600;
document.write("Year: " + year5 + "<br>");
if(isLeapYear(year5)) {
document.write(year5 + " is a leap year" + "<br>");
} else {
document.write(year5 + " is not a leap year" + "<br>");
}

Output:

Year: 2021
2021 is not a leap year
Year: 2012
2012 is a leap year
Year: 1980
1980 is a leap year
Year: 1990
1990 is not a leap year
Year: 1600
1600 is a leap year

Related: Functional Programming Languages You Should Know

C Program to Check Whether a Year Is a Leap Year or Not

Below is the C program to check whether a given year is a leap year or not:

// C program to check if a given year is a leap year or not
#include <stdio.h>
#include <stdbool.h>
bool isLeapYear(int y)
{
// If a year is a multiple of 4 and not a multiple of 100 or a multiple of 400,
// then the year is a leap year
// Multiple of 4 and (Not a multiple of 100 or Multiple of 400) => A Leap year
return (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0));
}
int main()
{
int year1 = 2021;
printf("Year: %d \⁠n", year1);
if(isLeapYear(year1))
{
printf("%d is a leap year \⁠n", year1);
}
else
{
printf("%d is not a leap year \⁠n", year1);
}
int year2 = 2012;
printf("Year: %d \⁠n", year2);
if(isLeapYear(year2))
{
printf("%d is a leap year \⁠n", year2);
}
else
{
printf("%d is not a leap year \⁠n", year2);
}
int year3 = 1980;
printf("Year: %d \⁠n", year3);
if(isLeapYear(year3))
{
printf("%d is a leap year \⁠n", year3);
}
else
{
printf("%d is not a leap year \⁠n", year3);
}
int year4 = 1990;
printf("Year: %d \⁠n", year4);
if(isLeapYear(year4))
{
printf("%d is a leap year \⁠n", year4);
}
else
{
printf("%d is not a leap year \⁠n", year4);
}
int year5 = 1600;
printf("Year: %d \⁠n", year5);
if(isLeapYear(year5))
{
printf("%d is a leap year \⁠n", year5);
}
else
{
printf("%d is not a leap year \⁠n", year5);
}
return 0;
}

Output:

Year: 2021
2021 is not a leap year
Year: 2012
2012 is a leap year
Year: 1980
1980 is a leap year
Year: 1990
1990 is not a leap year
Year: 1600
1600 is a leap year

Make Programming Easier Using Coding Apps

If you’re looking out for a fun way to learn to code, you can use some apps like Enki, Grasshopper, SoloLearn, Codeacademy Go, Hopscotch, Encode, etc. These apps provide great environments for learning to code in a fun and interactive way. They’ll help you stay on top of your game by coding wherever you are.

MUO – Feed

  • Tweet
Tagged under: Check, Languages, Leap, Multiple, Year

About Malika Karoum

What you can read next

A Guide to Every Angry Birds Game Ever Released
10 Deals on VPNs, Online Courses, Mac Apps, Gadgets, And More
Facebook Portal Makes Video Calling Easier

Malika Karoum Blog 2023

  • Windows 11’s 22H2 Release Date Finally Appears Online

    Windows 11 has had the chance to prove itself t...
  • 8 Simple Photography Genres for Beginners to Try

    Even if you’ve just picked up photography...
  • How to Change the Name of Your Mac

    When you set up your Mac for the first time, Ap...
  • 3 Different Ways to Remotely Record a Podcast Interview

    At some point in your podcasting journey you wi...
  • What Size Should Your Instagram Photos and Videos Be?

    Being a completely visual platform, Instagram h...
  • The 10 Best Raspberry Pi IoT Projects

    Launched in 2012, the Raspberry Pi single-board...
  • 5 Rust WebAssembly Frameworks for Your Next Application

    WebAssembly (WASM) is a portable, low-level bin...
  • How to Switch Off Live Captions in Chrome

    Chrome's Live Caption feature automatically...
  • What to Do if You Drop Your Kindle in Water

    Everyone knows that paper books and water don&#...
  • The Differences Between Level 1, Level 2, and Level 3 EV Charging Explained

    EVs are now omnipresent, and you're probabl...
  • 6 Fixes for AirPods Not Switching Automatically Between Apple Devices

    Whenever you make a call, play some music, or w...
  • The Most Fun Workout Tutorials on YouTube

    Who says exercise has to be a serious endeavor?...
  • Remove the GarageBand Sound Library From Your Mac to Save Storage

    Every Mac comes with GarageBand pre-installed. ...
  • How to Control Your Mouse With the Keyboard in macOS

    Back in the day, before computer mice and track...
  • How to Turn Off Google Assistant on Android, Chromebook, and Smart Devices

    Virtual assistants such as Amazon’s Alexa...
  • Get a Lifetime Microsoft Windows 10 License for $14, Office for $26 

    When you have a Microsoft Windows license, you ...
  • Manage Passwords and Private Data With Keeper

    The many companies with which we all have accou...
  • How to Remove Items From the New Context Menu in Windows 10-11

    Streamlining Microsoft Windows to make it suit ...
  • Geekom’s IT8 Mini PC Is a Palm-Sized, Portable, Powerhouse ‘Puter

    Is your workspace crying out for some additiona...
  • A Beginner’s Guide to Reddit: 9 Tips for New Users

    Reddit can be a daunting place for new users. W...

MALIKA KAROUM ONLINE MARKETING PLATFORM

Office:
RME HOLDINGS SARL – DUBAI BRANCH

BUSINESS CENTER

Parcel ID: 345-835

Area: Bur Dubai

Sub Area: Burj Khalifa

UNITED ARAB EMIRATES

 

 

 

Malika Karoum Concept

Malika Karoum Projects

  • GET SOCIAL

© 2014 Malika Karoum -United Arab Emirate Dubai- All Rights Reserved

TOP