To prepare for your final exam, you should try to solve as many problems as possible on the page. I recommend you should try to solve all of them! Later we will release solutions for some of the problems, however, please note that we will not release solutions for all the questions. Best way to learn is to try to solve a problem before reading it's possible solution.
The following questions use this datatype from lectures:
struct node { int data; struct node *next; };
See list_empty.c and list.h for some of the questions on linked list below, and testList.c for autotests. Alternatively download all three files at tut_list_files.zip.
int ordered(struct node *head);
answer: order.c.
int identical(struct node *head1, struct node *head2);
answer: identical.c.
struct node *copy(struct node *head);It should call malloc to create a new linked list of the same length and which contains the same data.
answer: copy.c.
The new linked list should also be in strictly increasing order. It should include only elements found in both lists.
set_intersection should call malloc to create the nodes of the new linked list.
set_intersection should have this prototype:
struct node *set_intersection(struct node *set1, struct node *set2);
thirteen_stdin.c
which reads 2 integers from standard input
and then prints all integers divisible
by 13 between those numbers.
Your program should behave like this:
./a.out Enter start: 10 Enter finish: 42 13 26 39
Your program should behave like this:
./a.out 10 42 13 26 39
If error checking was required - what checking would you add to the programs from the previous 2 questions?
median.c
which reads integers until end-of-input is reached.
It should then print the median (middle) of the integers.
If there are an even number of integer you can print either of the two middle integers.
Assume the numbers of integer is > 0 and < 1000.
Assume the integer are entered in sorted (non-decreasing) order.
Your program should behave like this:
./a.out 1 2 4 8 16 5 numbers read. Median was 4
int remove_char(char str[], char c)
For example "carpark" and "carpet" have a common prefix length of 4.
// text - the array of strings // array_size - the number of strings in the array // num_chars - print out any strings in the array with more than this number // of characters void print_if_longer(int array_size, char text[array_size][MAX_LEN], int num_chars);
int x = -9; int *p1 = &x; int *p2; p2 = p1; printf("%d\n", *p2); *p2 = 10; printf("%d\n",x);
int x = -9; int y = 0; while (x != 0){ y = y - 1; x = x + 1; } printf("%d\n", x); printf("%d\n",y);
int i = -7; int j = 0; while (i != 0){ j = j - i; i = i + 1; } printf("%d\n", i); printf("%d\n",j);
char goals[] = "All your goals belong to us."; char *a, *b, *c; a = goals + 5; b = &goals[10]; c = goals + (b - goals) + (b - a);The fragment is valid C. It executes without error. Indicate clearly and exactly what the following expressions evaluate to:
a == goals
a > goals
goals > c
c - b
goals - a
a[0] != b[0]
*c
goals[a - goals] == *a
c[a - b]
int i = 0; int j = 0; char *s = "ceded"; while (s[i] != '\0') { j = j + s[i] - 'a'; i = i + 1; } printf("%d %d\n", i, j);The fragment is valid C. It executes without error. Indicate clearly and exactly what output will be printed.