View Single Post
Old 09-28-2005, 03:59 AM   #3 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
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;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001

Last edited by redhead; 09-28-2005 at 03:57 PM.
redhead is offline   Reply With Quote