Skip to content

Instantly share code, notes, and snippets.

@awmpietro
Created December 12, 2017 13:58
Show Gist options
  • Select an option

  • Save awmpietro/281eac6e4973381ffd978cde2fd88185 to your computer and use it in GitHub Desktop.

Select an option

Save awmpietro/281eac6e4973381ffd978cde2fd88185 to your computer and use it in GitHub Desktop.
Calculate a leap year in C
int main() {
int year;
printf("Enter year");
scanf("%d", &year);
if(year % 4 == 0) {
if(year % 100 == 0) {
if(year % 400 == 0) {
printf("Yes, the year is leap year\n");
} else {
printf("No, this is not a leap year\n");
}
} else {
printf("Yes, the year is leap year\n");
}
} else {
printf("No, this is not a leap year\n");
}
}
@awmpietro
Copy link
Author

if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) printf("Yes, the year is leap year\n");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment