 # Leap Years

This is a companion discussion topic for the original entry at https://toph.co/p/leap-years

Please make it clear that this problem uses an incorrect definition of “leap year”.
It says incorrectly “A leap year occurs when the year is a multiple of 4 but not a multiple of 400”.
The correct definition is “Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 are not leap years, but the year 2000 is”.

1 Like

@Quandray Thank you for pointing this out.

what is the problem in this code???

``````#include<stdio.h>
int main()
{
int Y;
scanf("%d",&Y);
Y>9999;
{

if(Y%4==0)
{
printf("Yes");
}
else if(Y%400==0)
{
printf("No");
}
else if(Y%100==0)
{
printf("No");
}
else
{
printf("No");
}
}
return 0;
}
``````

Actually, for this problem, you have to check if a year is equally divisible by 4 or not only.
It is not a proper leap year.
Read the problem statement carefully and try again.

#include <stdio.h>

int main() {
int a;
scanf("%d",&a);
if(a%4==0){
printf(“Yes”);
}
else if(a%400==0){
printf(“No”);
}
return 0;
}

problem???

In this problem, every year which is equally divided by 4 is a leap year.
You have to do nothing more to get AC.

1 Like
``````#include <stdio.h>
#include <stdlib.h>

int main()
{
int year;
scanf("%d",&year);

if
(year%400==0)
printf("Yes");
else if
(year%4==0 && year%100!=0)
printf("Yes");

else
printf("No");

return 0;
}
``````

WHATS WRONG WITH IT??

You should check previous posts before posting your problems.

``whats the problem ?
#include<stdio.h>
int main() {
int Y;
scanf("%d",&Y);
if(Y%4==0)
{ printf(“Yes”);
}
else
{ printf(“No”);
}
return 0;
}

#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
if(n%400==0){
printf(“Yes”);
}
else if(n%4==0&&n%100!=0){
printf(“Yes”);
}
else{
printf(“No”);
}
return 0;
}

i could not understand where is the problem . please tell me clearly where the problem. it will be better if anyone give the answer in bangla

Read the problem statement carefully again.

In this problem, any year which can be equally divided by 4 is considered as a leap year. So, That much logic is not required.

What is the problem is my code can you please fix it?

#include <stdio.h>

int is_leap_year(int year)
{
return (!(year % 4)) ? 1 : 0;
}

int main()
{
int key, end, year;
scanf("%d",&year);
for (key = 0; key < 9999; ++key) {

``````    printf(year, (is_leap_year(year) == 1 ? "Yes" : "No"));
}
``````

}

year % 4 can return 0, 1, 2 or 3 and the not `(!)` operator you are using is not logical but bit wise. However this might a bit difficult to explain so, I will ditch the explaination.

To put it simply, Your the `int is_leap_year()` is will never actually return 1. So, your code should always print No.

Just write something like

``````return ( year % 4 == 0 ) ? 1 : 0; or,
return ( year % 4 != 0 ) ? 0 : 1;
``````
1 Like

Thanks elder your suggestion,I have successfully fix it before .
I use return (year % 400!=0 && year % 4 ==0) ? 1 : 0;
and its works. I have to fix for loop here which was wrong.

Whats wrong here?

``````#include <stdio.h>

int main() {
int a;
scanf("%d", &a);
if (a%4 == 0) printf("Yes");
else printf("No");
return 0;
}
``````

import java.util.Scanner;
public class toph_leapyear{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
int Y=input.nextInt();
if(Y<9999 && Y>0){
if(Y%4==0){
if(Y%400!=0){
System.out.println(“Yes”);
}
}
else{
System.out.println(“No”);
}
}
}
}

//where is the problem?!

year = int(input(""))

print(“Yes”) if year%4 == 0 else print(“No”)

Where is my problem here? ``````n = int(input())
if n % 4 == 0:
print('Yes')
else:
print('No')
``````

This is supposed to be working as @touhidur is saying that you only need to check if the
input is exactly divisible by 4 or not… but it doesn’t work on the 2nd test case.