-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircles.c
33 lines (26 loc) · 836 Bytes
/
circles.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* Patterns for Beginning Programmers (David Bernstein) */
/* I Patterns Requiring Knowledge of Types, Variables, and Arithmetic Operators
*/
/* 4. Arithmetic on the circle */
/* Example Program: calculate weekday */
/* Compile with `gcc circles.c -o circles` */
#include <stdlib.h>
#include <stdio.h>
int advanceWeekday(int currentDay, int daysToAdvance) {
int cardinality = 7;
return (currentDay + daysToAdvance) % cardinality;
}
int main(void)
{
int day;
printf("Enter current day number (0-6): ");
scanf(" %d", &day);
int toAdvance;
printf("Enter days to advance: ");
scanf(" %d", &toAdvance);
printf("Resulting weekday: %d\n", advanceWeekday(day, toAdvance));
int cardinality = 7;
int passes = (day + toAdvance) / cardinality;
printf("%d mondays in between\n", passes);
return EXIT_SUCCESS;
}