Something like:
Code:
#include <stdio.h>
#include <stdlib.h>
#define LENGTH 6
int leap_year(int* year);
int main(){
char buffer[LENGTH +1];
int year_from, year_to;
unsigned short int add = 1;
printf("Enter year From: ");
fflush(stdout);
if(!fgets(buffer, LENGTH, stdin))
{
printf("Error reading from stdin\n");
return -1;
}
year_from = strtol(buffer,(char **)NULL, 10);
if(year_from < 0)
{
printf("Error getting year from\n");
return -1;
}
printf("Enter year To: ");
fflush(stdout);
if(!fgets(buffer, LENGTH, stdin))
{
printf("Error reading from stdin\n");
return -1;
}
year_to = strtol(buffer,(char **)NULL, 10);
if(year_to <= year_from)
{
add = 0;
}
while(1)
{
if(add)
{
if(year_from > year_to)
break;
}
else
if(year_to > year_from)
break;
if(leap_year(&year_from))
printf("%d\n", year_from);
if(add)
++year_from;
else
year_from--;
}
return 0;
}
int leap_year(int* year)
{
if(!(*year%400))
return 1;
if(!(*year%100))
return 0;
if(!(*year%4))
return 1;
return 0;
}