Is there a simpler test for leap year in C?
Is there any shorter logic than this to achieve leap year test with fewer conditions? #include <stdio.h> int isleap(int year) { return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); } int main() { for (int year = 1600; year <= 2020; year++) { printf("%d: %s\n", year, isleap(year) ? "Leap Year" : "Not a Leap Year"); } return 0; }
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.