Program Discussion :: Basics
70 / 279
Write a program to check whether the entered year is leap year or not?
Answer:
#include
# include
using namespace std;
int main()
{
int year;
cout year;
if(year%4 == 0)
{
if( year%100 == 0)
{
/* year is divisible by 400, hence the year is a leap year */
if ( year%400 == 0)
cout
Asked In ::
Language:
Pankaj
24 Jun, 2017 5:27 PM
<!DOCTYPE html>
<html>
<body>
<?php
$x = 1998;
if ((($x % 4 == 0) && ($x % 100 != 0)) || ($x % 400 == 0)) {
echo ("this is a leap year");
}
else {
echo ("this is not a leap year");
}
?>
</body>
</html>
Language:
Ganesh
7 Jul, 2017 9:30 AM
#include <stdio.h>
int main()
{
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);
return 0;
}
Language:
Varun
7 Jul, 2017 9:30 AM
#include <stdio.h>
# include <iostream>
using namespace std;
int main()
{
int year;
cout <<"Enter a year: ";
cin>>year;
if(year%4 == 0)
{
if( year%100 == 0)
{
/* year is divisible by 400, hence the year is a leap year */
if ( year%400 == 0)
cout << year<<"is a leap year."<< year;
else
cout<< year <<" is not a leap year."<<year;
}
else
cout<< year <<" is a leap year."<< year;
}
else
cout<< year <<" is not a leap year." <<year;
getch();
return 0;
}
Language:
Siddhartha Paul
19 Jun, 2019 2:16 PM
import java.io.*;
public class LeapYear
{
public static void main(String []args)throws IOException
{
int f=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a year: ");
int year=Integer.parseInt(br.readLine());
if((year%400)==0)
f=1;
else if((year%100)==0)
f=0;
else if((year%4)==0)
f=1;
else
f=0;
if(f==1)
System.out.println(year+" is a leap year!!");
else
System.out.println(year+" is not a leap year!!");
}
}