# checking a leap year

• 04-10-2007
elton_fan
checking a leap year
hello everyone
can i use the statement below to check wether a year is leap or not
the statement is
if((year%100== 0 && year%400==0) || (year%100!=0&&year%4==0))
feb=29;
else
feb=28;
• 04-10-2007
MacGyver
Why don't you test it and find out?
• 04-10-2007
Salem
Yes, something like that should work just fine.

I assume there is a followup "doesn't work" question coming....
• 04-10-2007
elton_fan
excuse me salem what did you mean ?
• 04-10-2007
He's expecting the "other shoe to fall" i.e.:

"I've been trying to get this to work in my assignment, but it just won't give me the right results".
:)

Personally, I like to enclose compound statements like that if statement, in their own seperate parenthesis, so the bug of operator precedence doesn't bite me too often.

• 04-10-2007
robatino
If the year is divisible by 400, then it's also divisible by 100 so you don't need to check both.
• 04-10-2007
elton_fan
do you think just by integrating braces everything is going to be all right
• 04-10-2007
Salem
Yes, the shoe event horizon looms large.

Basically, you've asked a "meta" question as a disguise of your real question.

So we just waste a bunch of time pratting about with the obvious until you get around to the real problem which you're facing.