/* File: mycal3.c Step 3 in writing my version of the calendar program. This program prints several months, all with 31 days. */ void PrintOneMonth(int start, int days) ; int AddDay(int weekday, int inc) ; main() { int start, months, i ; int weekday, inc, next ; printf("start =? ") ; start = GetInteger() ; printf("months =? ") ; months = GetInteger() ; for (i = 0 ; i < months ; i++) { PrintOneMonth(start, 31) ; start = AddDay(start, 31) ; } } int AddDay(int weekday, int inc) { return( (weekday + inc) % 7 ) ; } void PrintOneMonth(int start, int days) { int i ; /* Indent the first line */ for (i = 0 ; i < start ; i++) { printf(" ") ; } for (i = 1 ; i <= days ; i++) { printf("%3d", i) ; /* print newline at end of week */ if ( (i + start) % 7 == 0 ) { printf("\n") ; } } /* Print newline at end of month only if necessary */ if( (i + start) % 7 != 1) { printf("\n") ; } }