Description
- (Arithmetic)There is a 5-digit number that satisfies 4·abcde = edcba, that is, when multiplied by 4 yields the same number read backwards. Write a C-program to find this number.
- (Arrays)
- Write a C-function that returns the inner product of two n-dimensional vectors a and b, encoded as 1-dimensional arrays of n floating point numbers.
Use the function prototype float innerProduct(float a[], float b[], int n).
Hint: The inner product of two vectors is calculated as ∑i=1..nai⋅bi∑i=1..nai⋅bi
- Write a C-function to compute C as the matrix product of matrices A and B.
Use the function prototype void matrixProduct(float a[M][N], float b[N][P], float c[M][P]).
You can assume that M, N, P are given as symbolic constants, e.g.#define M 3 #define N 4 #define P 4
Hint: The product of an m×n matrix A and an n×p matrix B is the m×p matrix C such that Cij=∑k=1..nAik⋅BkjCij=∑k=1..nAik⋅Bkj for all i∈{1..m} and j∈{1..p}.
- Write a C-function that returns the inner product of two n-dimensional vectors a and b, encoded as 1-dimensional arrays of n floating point numbers.
- (Characters)Write a C-program that outputs, in alphabetical order, all strings that use each of the characters ‘c’, ‘a’, ‘t’, ‘d’, ‘o’, ‘g’ exactly once.
How many strings does the program generate?
- (Elementary control structures)
- Write a C-function that takes a positive integer n as argument and outputs a series of numbers according to the following process, until 1 is reached:
- if n is even, then n ← n/2
- if n is odd, then n ← 3*n+1
- The Fibonacci numbers are defined as follows:
- Fib(1) = 1
- Fib(2) = 1
- Fib(n) = Fib(n-1)+Fib(n-2) for n≥3
Write a C program fibonacci.c that applies the process described in Part a. to the first 10 Fibonacci numbers.
The output of the program should begin with
Fib[1] = 1 1 Fib[2] = 1 1 Fib[3] = 2 2 1 Fib[4] = 3 3 10 5 16 8 4 2 1
We have created a script that can automatically test your program. To run this test you can execute the dryrun program that corresponds to the problem set and week, i.e. prob01 for this week. It expects to find a program named fibonacci.c in the current directory. You can use dryrun as follows:
~cs9024/bin/dryrun prob01a
Note: Please ensure that your output follows exactly the format shown above.
- Write a C-function that takes a positive integer n as argument and outputs a series of numbers according to the following process, until 1 is reached:
- (Elementary data structures)Define a data structure to store all information of a single ride with the Opal card. Here are two sample records:
You may assume that individual stops (such as “Anzac Pde D opp UNSW”) require no more than 31 characters.
Determine the memory requirements of your data structure, assuming that each integer and floating point number takes 4 bytes.
If you want to store millions of records, how would you improve your data structure?
- Challenge ExerciseWrite a C-function that takes 3 integers as arguments and returns the largest of them. The following restrictions apply:
- You are not permitted to use if statements.
- You are not permitted to use loops (e.g. while).
- You are not permitted to call any function.
- You are only permitted to use data and control structures introduced in Week 1’s lecture.