C Program to Check Whether a Year is a Leap Year or Not वर्ष Leap Year है या नहीं, जाँचने का C Program

A leap year contains 366 days instead of 365 days. February has 29 days in a leap year.

Leap year में 365 के स्थान पर 366 दिन होते हैं। ऐसे वर्ष में February में 28 के बजाय 29 दिन होते हैं।

Leap Year Formula

A year is a leap year if:

  • It is divisible by 400, OR

  • It is divisible by 4 but not divisible by 100.

Formula:

(year % 400 == 0) ||
((year % 4 == 0) && (year % 100 != 0))

Hindi Explanation:

कोई वर्ष Leap Year होता है यदि वह 400 से divisible हो, या 4 से divisible हो लेकिन 100 से divisible न हो।

C Program

#include <stdio.h>
int main(void)
{
int year;
printf("Enter a year\n");
scanf("%d", &year);
if (year % 400 == 0)
printf("%d is a leap year\n", year);
else if (year % 100 == 0)
printf("%d is not a leap year\n", year);
else if (year % 4 == 0)
printf("%d is a leap year\n", year);
else
printf("%d is not a leap year\n", year);
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

Example 4:

Enter a year
2023
2023 is not a leap year

Explanation

  • year % 400 == 0 checks whether the year is divisible by 400.

  • year % 100 == 0 checks whether the year is divisible by 100.

  • year % 4 == 0 checks whether the year is divisible by 4.

  • The if-else if-else statement determines whether the year is a leap year.

यह program % (modulus) operator का उपयोग करके year की divisibility जाँचता है। if-else if-else statement के माध्यम से यह निर्धारित किया जाता है कि दिया गया वर्ष Leap Year है या नहीं।

Modern C Compatibility Note

This program uses standard C and is compatible with modern compilers such as GCC, Clang, and Visual Studio C. It does not require non-standard functions like clrscr() or getch().

This program demonstrates how to use the Leap Year formula, if-else if-else statement, and modulus operator to check whether a given year is a leap year.

यह program Leap Year formula, if-else if-else statement और modulus operator का उपयोग करके Leap Year की जाँच करना सिखाता है।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025