Program to Check Given Year is Leap Year or Not
- Write a program to Check if Given Year is Leap Year or Not in C
- Write a program to Check if Given Year is Leap Year or Not in C++
- Write a program to Check if Given Year is Leap Year or Not in Python
- Write a program to Check if Given Year is Leap Year or Not in PHP
- Write a program to Check if Given Year is Leap Year or Not in Java
- Write a program to Check if Given Year is Leap Year or Not in Java Script
- Write a program to Check if Given Year is Leap Year or Not in C#
Explanation:
o check if a given year is a leap year:
Leap Year Rules
- A year is a leap year if:
- It is divisible by 4.
- But, if it is divisible by 100, it must also be divisible by 400.
- This means:
- Years like 1600, 2000, 2400 are leap years (divisible by 400).
- Years like 1700, 1800, 1900 are not leap years (divisible by 100 but not by 400).
- Years like 2024, 2028 are leap years (divisible by 4 but not by 100).
Program to Check Given Year is Leap Year or Not
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h>
int main() {
int year;
// Input the year
printf("Enter a year: ");
scanf("%d", &year);
// Check if the year is a leap year
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
printf("%d is a leap year.\n", year);
} else {
printf("%d is not a leap year.\n", year);
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int year;
// Input the year
cout << "Enter a year: ";
cin >> year;
// Check if the year is a leap year
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
cout << year << " is a leap year." << endl;
} else {
cout << year << " is not a leap year." << endl;
}
return 0;
}
year = int(input("Enter a year: "))
# Check if the year is a leap year
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(f"{year} is a leap year.")
else:
print(f"{year} is not a leap year.")
<?php
// Input the year
$year = (int)readline("Enter a year: ");
// Check if the year is a leap year
if (($year % 4 == 0 && $year % 100 != 0) || ($year % 400 == 0)) {
echo "$year is a leap year.\n";
} else {
echo "$year is not a leap year.\n";
}
?>
import java.util.Scanner;
public class LeapYearCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input the year
System.out.print("Enter a year: ");
int year = scanner.nextInt();
// Check if the year is a leap year
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
System.out.println(year + " is a leap year.");
} else {
System.out.println(year + " is not a leap year.");
}
scanner.close();
}
}
let year = parseInt(prompt("Enter a year: "));
// Check if the year is a leap year
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
console.log(year + " is a leap year.");
} else {
console.log(year + " is not a leap year.");
}
using System;
class Program {
static void Main() {
// Input the year
Console.Write("Enter a year: ");
int year = Convert.ToInt32(Console.ReadLine());
// Check if the year is a leap year
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
Console.WriteLine(year + " is a leap year.");
} else {
Console.WriteLine(year + " is not a leap year.");
}
}
}