C++ Program to Check Whether a Given Year is a Leap Year or Not (दिया गया वर्ष Leap Year है या नहीं, जाँचने का C++ प्रोग्राम)

A Leap Year is a year that contains 366 days instead of the usual 365 days. February has 29 days in a leap year instead of 28 days. A year is a leap year if It is completely divisible by 400, or It is divisible by 4 but not divisible by 100.

Leap Year वह वर्ष होता है जिसमें सामान्य 365 दिनों के स्थान पर 366 दिन होते हैं। सामान्य वर्ष में February के 28 दिन होते हैं, जबकि Leap Year में February के 29 दिन होते हैं। किसी वर्ष को Leap Year माना जाता है यदि वह 400 से पूर्णतः विभाजित हो, अथवा 4 से विभाजित हो लेकिन 100 से विभाजित न हो।

C++ Program

#include <iostream>
using namespace std;
int main()
{
int year;
cout << "Enter a year: ";
cin >> year;
if (year % 400 == 0)
{
cout << year << " is a leap year." << endl;
}
else
{
if (year % 100 == 0)
{
cout << year << " is not a leap year." << endl;
}
else
{
if (year % 4 == 0)
{
cout << year << " is a leap year." << endl;
}
else
{
cout << year << " is not a leap year." << endl;
}
}
}
return 0;
}

Output (आउटपुट)

Example 1:

Enter a year: 2024
2024 is a leap year.

Example 2:

Enter a year: 1900
1900 is not a leap year.

Example 3:

Enter a year: 2000
2000 is a leap year.

Explanation (व्याख्या)

The program uses nested if-else statements and the modulus (%) operator to check whether a year is divisible by 400, 100, or 4.

  • year % 400 == 0: The year is a leap year.

  • year % 100 == 0: The year is not a leap year.

  • year % 4 == 0: The year is a leap year.

  • Otherwise, it is not a leap year.

इस प्रोग्राम में Nested if-else Statements का उपयोग किया गया है। % (Modulus) Operator किसी संख्या को दूसरी संख्या से विभाजित करने पर प्राप्त शेषफल बताता है। सबसे पहले जाँच की जाती है कि वर्ष 400 से विभाजित होता है या नहीं। यदि होता है, तो वह Leap Year है। अन्यथा 100 से विभाजित होने की जाँच की जाती है। यदि वह 100 से विभाजित होता है, तो वह Leap Year नहीं है। अंत में 4 से विभाजित होने की जाँच की जाती है। यदि शेषफल 0 आता है, तो वह Leap Year होता है।

Important Examples (महत्वपूर्ण उदाहरण)

YearResultReason
2024Leap YearDivisible by 4, not by 100
2025Not Leap YearNot divisible by 4
1900Not Leap YearDivisible by 100, not by 400
2000Leap YearDivisible by 400

This program demonstrates the use of nested if-else statements and the modulus operator in C++ to determine whether a given year is a leap year.

यह प्रोग्राम C++ में Nested if-else Statements और Modulus Operator की सहायता से यह जाँच करना सिखाता है कि दिया गया वर्ष Leap Year है या नहीं।

Comments

Popular posts from this blog

Important Questions (IMP) of Programming Methodologies and Data structures using C++ with OOP's Concepts

Complete C++ Programming Syllabus - From Basics to Advanced C++ , including OOP and Data Structures and Algorithms

OOP's using CPP Syllabus AND Programming Methodologies and Data Structures Using C++ (NEP 2020)