# 58127-1 C-ohjelmointi - Autumn 1998

## Exercises 5, 11/23 - 11/27 (course book pp. 1-150,167)

You have to answer at least 3 of the following questions/write the programs to qualify in these exercises!

1. Write a function roots that solves a second degree equation ax2+bx+c=0. Write then a program that recieves a,b, and c from command line and prints the roots of the equation. You can assume that a, b, and c are integers.

Hint: math.h has a function double sqrt(double x); that returns the square root of its parameter. In unix environment you have to add an option -lm to the compilation. For instance gcc -Wall -ansi t5_1.c -lm

2. Write a function that calculates the sum of two 10*10 matrixes. Return the result in a pointer argument. A 10*10 matrix is a 10*10 two-dimensional array. Write a main program to test your function.
3. Write a program using pointer arrays that translates numbers in input to a text form: 0 = zero, 1 = one, ... ,9 = nine. Don't use switch or else-if statements. Other characters of input are printed in the regular way.
4. Write a program that removes words from its input. The removed words are given as command line arguments. Write a function
```     char *remove(char *line, char *word);
```
that removes a word from a line. Be prepared to handle several removable words.

5. Design appropriate structures for complex numbers. Write functions for add and multiply operators that use complex numbers, and for displaying a complex number. You can expect the numbers to be of form a+bi where a and b are integers.
6. Write a simple command line interpreter (a shell) using pointers to functions. You don't have to implement the commands themselves, but adding new commands must be straightforward. It is enough that the right function is called once a command is invoked. The called functions are of type
```     int command_name(char *parameters);
```
where command_name is the name of the called command and parameters is a string of its parameters. The functions return a non-zero value when they succeed. Write also a main program where you test the shell program. Every command in the test case only prints its name and parameters.