Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(void) {
- struct list {
- char name[20];
- struct list *prev, *next;
- } zodiac[] = {{.name = "boar"}, {.name = "rat"}, {.name = "ox"},
- {.name = "tiger"}, {.name = "rabbit"}, {.name = "dragon"},
- {.name = "snake"}, {.name = "horse"}, {.name = "sheep"},
- {.name = "monkey"}, {.name = "rooster"}, {.name = "dog"}};
- size_t size = sizeof(zodiac) / sizeof(zodiac[0]);
- for (size_t i = 0; i < size; ++i) {
- zodiac[i].next = &zodiac[(i + 1) % size];
- zodiac[(i + 1) % size].prev = &zodiac[i];
- }
- struct list *current = &zodiac[0];
- printf("This year is [%s] in oriental zodiac.\n", current->name);
- for (int i = 0; i < 5; ++i) {
- printf("Please enter how many years to move =>");
- int move;
- if (scanf("%d", &move) != 1) {
- exit(1);
- }
- move %= size;
- move += size;
- move %= size;
- for (int j = 0; j < move; ++j) {
- current = current->next;
- }
- printf("This year is [%s] in oriental zodiac.\n", current->name);
- }
- puts("Finish.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement