Problem Statement:- Program to find whether an entered year is a leap year or not using function.
Data requirement:-
Input Data:-Year
Output Data:-String Output
Output Data:-String Output
Program in C
Here is the source code of the C Program to Check whether a year is a leap year or not.
Code:
#include<stdio.h>
int main()
{
int year;
printf("Enter a year:");
scanf("%d",&year);
if((year%100==0 && year%400==0) || (year%100!=0 && year%4==0))
printf("It is a Leap Year");
else
printf("It is not a Leap Year");
}
Input/Output:
Enter a year:1888It is a Leap Year
Program in C++
Here is the source code of the C++ Program to Check whether a year is a leap year or not.
Code:
#include<iostream>
using namespace std;
int main()
{
int year;
cout<<"Enter a year:";
cin>>year;
if((year%100==0 && year%400==0) || (year%100!=0 && year%4==0))
cout<<"It is a Leap Year";
else
cout<<"It is not a Leap Year";
}
Input/Output:
Enter a year:2002
It is not a Leap Year
Program in Java
Here is the source code of the Java Program to Check whether a year is a leap year or not.
Code:
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int year;
System.out.println("Enter a year:");
year=cs.nextInt();
if((year%100==0 && year%400==0) || (year%100!=0 && year%4==0))
System.out.println("It is a Leap Year");
else
System.out.println("It is not a Leap Year");
cs.close();
}
}
Input/Output:
Enter a year:
2016
It is a Leap Year
Program in Python
Here is the source code of the Python Program to Check whether a year is a leap year or not.
Code:
if ((year % 100 == 0 and year % 400 == 0) or (year % 100 != 0 and year % 4 == 0)):
print("It is a Leap Year")
else:
print("It is not a Leap Year")
Input/Output:
Enter a Year:2050
It is not a Leap Year
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box