예제 #1
0
int main (void) {
    /* this is the year that is inputed */
    int year;
    /* this is to check whether the input has reached an end */
    int end;
    /* this is the day that calculate easter date returns */
    int day;
    /* this is the function prototype for calculate_easter date */
    int calculate_Easter_date (int year);
    while(1) {
        end = scanf("%d", &year);
        if (end == EOF) {
            break;
        }
        if ((year > 1581) && (year < 39999)) {
            day = calculate_Easter_date(year);
            if (day > 0) {
                printf("%d - April %d\n", year, day);
            }
            else {
                day = (-1) * day;
                printf("%d - March %d\n", year, day);
            }
        }
        else {
            fprintf(stderr, "year out of range");
        }

    }
    return 0;
}
예제 #2
0
파일: easter.c 프로젝트: shimmy1996/cs011
int main(void)
{
    /*This program computes the dates of easter of a given year. 
     * It only accepts input between 1582 to 39999.
     * If input is out of range, an error message will be printed.
     * It will also double check whether the answer is correct using
     * Zeller's Congruence.
     */
    int yr; /* the year imputed */
    int date;
    
    while(1)
    {
        if (scanf("%d", &yr)==EOF)
        {
            break;
        }
        date = calculate_Easter_date(yr);
        if (date > 0)
        {
            assert (is_Sunday(date, yr) == 1);
            printf("%d - April %d\n", yr, date);
        
        }
        else if (date < 0)
        {
            assert (is_Sunday(date, yr) == 1);
            printf("%d - March %d\n", yr, -date);
        }
        else
        {
            fprintf(stderr, "Invalid Year Input\n");
        }
    }
    return 0;
}