-5

Please explain what is happening in the code.

I tried the if else that did not work.

#include <stdio.h>

int isLeapYear(int year)
{
   return ((!(year % 4) && year % 100) || !(year % 400));
}
  • Looks fine to me. Please give a complete example of how it doesn't work. – Joseph Sible-Reinstate Monica Sep 29 '19 at 04:01
  • There is no *if else* in the code you've posted, and the leap year algorithm is well known and documented. Any semi-functional internet search engine should be able to find a result for *leap year calculation* - in fact, a very basic search of this site for [leap year calculation](https://stackoverflow.com/q/725098/62576) works. – Ken White Sep 29 '19 at 04:04

1 Answers1

1

Method to check whether the given year is leap year or not is

  1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
  2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
  3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
  4. The year is a leap year.
  5. The year is not a leap year.

Now Apply your if condition to above steps.

((!(year % 4) && year % 100) || !(year % 400))

1. !(year % 4)  --> is step1 
2. year % 100   --> is step2 
3. !(year % 400) --> is step3
kiran Biradar
  • 12,700
  • 3
  • 19
  • 44