Your tutor has asked a lab pair to present their week 4 work.
Discuss the good, the bad and the ugly aspects of their code.
Please be gentle in any criticism - we are all learning!
Hidden Sequence | Guess |
---|---|
4 4 4 4 | 4 4 4 4 |
1 1 1 1 | 4 4 4 4 |
1 4 1 1 | 4 4 1 4 |
1 1 4 1 | 4 4 1 4 |
1 2 3 4 | 4 3 2 1 |
1 2 3 4 | 2 1 3 4 |
5 6 7 8 | 6 6 7 7 |
1 8 2 7 | 7 8 1 2 |
1 1 2 3 | 4 1 1 1 |
1 2 2 1 | 2 2 2 2 |
srand(time(NULL)); printf("%d\n", rand() % 6 + 1);
numbers
int numbers[20];
and your program assigns a value to each element in the array, what is the problem with the statement x = numbers[20];
?
Write a C code fragment to store, in each element of this array, the square of the index of that element, e.g., squares[5] would contain the value 25.
int array_length(int nums[])which returns the number of elements in the array
nums
.
int test_all_initialized(int nums[])which returns 1 if all elements of array
nums
are initialized, otherwise returns 0.
int not_in_int_array(int nums[], int n, int x);
int dot_product(int vector1[VECTOR_LENGTH], int vector2[VECTOR_LENGTH])
Reminder: you calculate the dot product by multiplying corresponding elements and summing the result.
So the dot-product of 1 3 1 3 2 and 2 1 2 1 2 is 14.
Your tutor may still choose to cover some of the questions time permitting.
It should have this prototype:
double max_value(double array[], int length)
It should have this prototype:
int increasing(double array[], int length)
occur.c
which reads 6 numbers then reads another number
and prints how many times that number occurred in the first 5.
For example:
./occur Enter 6 numbers: 1 3 1 3 1 9 Enter a number: 1 1 occurred 3 times in the 6 numbers readMake sure you make you make it very easy to change how many numbers the program reads.
int x; int a[6]; x = 10; a[3 * 2] = 2 * 3 * 7; printf("%d\n", x);mysteriously printed
42
. How could this happen when x
is clearly
assigned only the value 10
?
How can you easily detect such errors before they have mysterious effects?
So if 9 numbers were entered the program should print the 5th number entered. And if 27 numbers were entered the program should print the 14th number entered.
If an even number of numbers is entered there are two middle numbers, print the second of them.
For example if 8 numbers are entered, prints the 5th.
You can assume at most 10,000 numbers will be entered.
double average(int numbers[], int num_elements);
double maxDifference(int numbers[], int num_elements);