Created
May 8, 2016 07:26
-
-
Save complxalgorithm/dd3e72721e4f50dcbda977875178f550 to your computer and use it in GitHub Desktop.
C program that will determine if an input year was/will be a leap year.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <ctype.h> | |
int main(){ | |
int year; | |
printf("Type a year (up to 4 digits) to determine if it's a leap year:"); | |
scanf("%d",&year); | |
getchar(); | |
if(((year<0)||(isalpha(year))||(year>9999))){ | |
printf("Invalid year. Try again.\n"); | |
}else{ | |
if((year%4==0)||(year%400==0)){ | |
if((year%4==0)&&(year%100==0)){ | |
printf("%d is not a leap year\n",year); | |
return 0; | |
} | |
printf("%d is a leap year.\n",year); | |
return 0; | |
} | |
printf("%d is not a leap year\n",year); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment