- #1
torquerotates
- 207
- 0
Maybe this should belong in the logic section. But since this is C++, ill put it here.
bool isLeapYear( int y)
{
return y%4==0 && y % 100 !=0 || y% 400==0 ;
}
They said it returns when y is divisible by 4 but not by 100 unless it is also divisible by 400.
This is a bit confusing since I thought that statements are binary. that is its either A and(BorC) or (AorB)andC. I mean we get statements like (A and B and B) b/c [A and (B and C)]=[A and B and C]. Same thing for the or operator. But I can't see how (A and B or C) results from a binary logical statement involving two sets.
Do they mean (y%4==0 && y % 100 !=0 || y% 400==0) is the same as
(y%4==0) && (y % 100 !=0 || y% 400==0)?
It would make a lot more sense b/c
(y%4==0) && (y % 100 !=0 || y% 400==0) is the same as
(y%4==0 && y % 100 !=0) ||(y%4==0 && y% 400==0)
which is the same as the statement:y is divisible by 4 but not by 100 unless it is also divisible by 400.
bool isLeapYear( int y)
{
return y%4==0 && y % 100 !=0 || y% 400==0 ;
}
They said it returns when y is divisible by 4 but not by 100 unless it is also divisible by 400.
This is a bit confusing since I thought that statements are binary. that is its either A and(BorC) or (AorB)andC. I mean we get statements like (A and B and B) b/c [A and (B and C)]=[A and B and C]. Same thing for the or operator. But I can't see how (A and B or C) results from a binary logical statement involving two sets.
Do they mean (y%4==0 && y % 100 !=0 || y% 400==0) is the same as
(y%4==0) && (y % 100 !=0 || y% 400==0)?
It would make a lot more sense b/c
(y%4==0) && (y % 100 !=0 || y% 400==0) is the same as
(y%4==0 && y % 100 !=0) ||(y%4==0 && y% 400==0)
which is the same as the statement:y is divisible by 4 but not by 100 unless it is also divisible by 400.