/* * Program to convert Julian date to month/day format. */ #include #define JAN 31 #define FEB 28 #define MAR 31 #define APR 30 #define MAY 31 #define JUN 30 #define JUL 31 #define AUG 31 #define SEP 30 #define OCT 31 #define NOV 30 #define DEC 31 int main(void) { int days_per_month[] = { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC }; int jdate; printf("enter julian date\n"); if (scanf("%d", &jdate) != 1) { printf("error -- non-numeric input\n"); return 1; } else if ((jdate < 1) || (jdate > 365)) { printf("error -- out of range (1 .. 365)\n"); return 1; } int month = 0; int days_left = jdate; while (days_left > days_per_month[month]) { days_left -= days_per_month[month]; month += 1; } month += 1; printf("julian date %d is %d/%02d\n", jdate, month, days_left); return 0; }