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));
}
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));
}
Method to check whether the given year is leap year or not is
- If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
- If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
- If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
- The year is a leap year.
- 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