Program to Check Leap Year

Description

A year is leap year having 366 days.
To implement in program it should follow the below condition

-> Year is multiple of 4 and not multiple of 100.
-> Year is multiple of 400.

C/C++

/* C Program to Check Leap Year */
//Save it as LeapYear.c

#include<stdio.h>
int main(){

    int year;

    printf("Enter the year : ");
    scanf("%d",&year);

    if(((year%4 == 0) && (year%100 != 0)) || (year%400 == 0)){
        printf("%d is a leap year",year);
    }else{
        printf("%d is not a leap year",year);
    }

    return 0;
}
Input:
Enter the year : 2012

Output:
2012 is a leap year

Java

/* Java Program to Check Leap Year */
//Save it as LeapYear.java

import java.io.*;
import java.util.Scanner;

public class LeapYear {

    public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
        
            int year;

        System.out.println("Enter the year : ");
        year = scanner.nextInt();

        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");
        }
    }
}
Input:
Enter the year : 
2012

Output:
2012 is a leap year

Related Programs

1) Simple Calculator Using If Else
2) Program to Find ASCII value of a character
3) Program To Check Armstrong Number
4) Program to Check Whether a Number is Even or Odd
5) Program to Check Whether a Character is a Vowel or Not
6) Program to Check Whether a Number is Prime or Not
7) Program to find greatest of 3 numbers
8) Check whether a given number is a perfect number or not
9) Program to find all prime numbers in given range
10) Program to swap two strings
Share Me

Leave a Reply