Proper Leap Years

Byang’s friend was asked to author a programming problem where the challenge was to identify if the …

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

Learn to Google.

However, methode to determine a leap year is simple.

  1. The year have to be evenly divided by 4 but not by 100.
  2. However, the year which is evenly divided by 400 is always a leap year.

Sauce: Leap Year

What’s wrong with my code here ?
C++

#include <stdio.h>
int main()
{
    int x;
    scanf("%d",&x);
	if(x%4 ==0){
		printf("Yes");
	}
               if(x%100 == 0 && x%400 == 0){
		printf("Yes");
	}

	else printf("No");

    return 0;
}


I'm getting wrong answer on the last test case here. The Gregorian criteria says It's a leap year if :
"The year can be evenly divided by 4;
If the year can be evenly divided by 100, it is NOT a leap year, unless;
The year is also evenly divisible by 400. Then it is a leap year."

Nevermind i fixed out. Did not understand the statement before.
#include <stdio.h>
int main()
{
int x;
scanf(“%d”,&x);
if(x%4 ==0 && x%100 !=0){
printf(“Yes”);
}
else if(x%400 == 0){
printf(“Yes”);
}

else printf("No");

return 0;

}
This one worked, so it’ll be a leap year ALWAYS if it is evenly divided by 400. and it’ll also be a leap year if it is evenly divided by 4 and also not evenly divided by 100

y=int(input())
if y%4==0 and y%100!=0:
print(‘yes’)
elif y%400==0 :
print(‘yes’)
else :
print(‘no’)
whats wrong?

see this.

Please check your “yes” and “no”…

what is wrong in it?
y = int(input())
if 0 < y < 9999:
if y % 4 == 0:
print(‘Yes’)
elif y % 100 == 0:
if y % 400 == 0:
print(‘Yes’)
else:
print(‘No’)

I don’t know why my code is getting wrong in the last test case… #python
< Code >

leap year again

user_input = int(input())

if user_input % 4 == 0 or user_input % 400 == 0 or user_input % 100 == 0:
print(“Yes”)

else:
print(“No”)

< Code End >

Help me out ! @hjr265

I know this is an old topic but as @touhidurrr stated.

However, methode to determine a leap year is simple.

  1. The year have to be evenly divided by 4 but not by 100.
  2. However, the year which is evenly divided by 400 is always a leap year.

You are checking whether the input is divisible without a remainder by 4 or by 400 or by 100. Over in this line:

if user_input % 4 == 0 or user_input % 400 == 0 or user_input % 100 == 0:

Rather you should check to see if the input is divisible by 4 and not divisible by 100. Then check if the requirements aren’t satisfied whether the input is divisible by 400. Finally if none of the two checks are triggered then printout No

Hopefully this helps out if anyone is having a problem :slight_smile:

.