Proper Leap Years


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

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: https://www.timeanddate.com/date/leapyear.html

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?

1 Like

see this.

Please check your “yes” and “no”…