Problem Set 1-a
Problem 1. 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.
Problem 2. Write a C program to compute the matrix product of two matrices A and B.
Problem 3. Write a C program that outputs, in alphabetical order, all the distinct strings that use each of
the characters ‘c’, ‘a’, ‘t’, ‘d’, ‘o’, ‘g’ exactly once. How many strings does the program generate?
Problem 4. 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, set n to n/2
• If n is odd, set n to 3*n+1
Problem 5. 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?
Problem 6. 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 Q4 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
Problem 7. Write a C function that takes 3 integers as arguments and returns the largest of them. Your C
function cannot use any control construct.
Problem 8. Write a C program that takes a sequence of integers from the keyboard, sorts them, and
displays the sorted sequence on the screen, one integer per line. A non-integer indicates the end of
sequence.