Skip to content

Instantly share code, notes, and snippets.

@complxalgorithm
Created May 8, 2016 07:26
Show Gist options
  • Save complxalgorithm/dd3e72721e4f50dcbda977875178f550 to your computer and use it in GitHub Desktop.
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.
#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