html>C-ohjelmointi, laskuharj. 1

C-programming Fall 1999

Problems for Exercise 5 (18.-22.10.1999)

Write your C-programs from the very beginning with a computer. Points will be given only for solutions proven by a computer. Make sure of the correct functioning by compiling your program, correcting possible errors and by running program, if necessary using different test inputs. Avoid using, in your solutions, such features that have not been explained in the course.

1. Write a program rect that prints out, using the given character a rectangular the width of of which is k character and the heigth n rows. The parameters width, heigth and the character used are given as command line arguments. See the example below.

Example
kruuna% rect 10 4 c
        cccccccccc 
        cccccccccc
        cccccccccc
        cccccccccc

2. Make your own version of the strcat function. The function catenates string s2 at the end of string s1. Parameter n gives the maximun length of string s1.

3. Write a program for making the command around. The command around writes out the strings gives as command line arguments in reverse order. For example around this is inverted prints out around siht si detrevni. Ps. The gcc compiler option -o around names the execution file as around (instead of a.out): gcc -Wall -ansi -o around .c

4. Write a program that randomly selects 7 lottery numbers and 3 extra numbers. Each number can appear only once. Partion your program into suitable functions. Make it possible to easily change the given numbers 7 and 3.

5. Write a function that counts the sum of two 10*10 matrixes. The matrixes are added by summing the peer elements. Return the result as a reference parameter. Write also a main program to test your function. 10*10 matrix is a two dimensional table.

6. Write a program that prints out the declarations (proto types) of functions Kirjoita ohjelma, joka tulostaa C-kielisestä ohjelmasta ohjelmassa that are defined in the program. For example if the functions int r(int maxvalue), void sort(int table[], int size) and void st(int table[], int size, int limit) are defined in the program the output would be :

      int r(int maxvalue);
      void sort(int table[], int size);
      void st(int table[], int size, int limit);
      int main();
Try to make your program as general as possible so that it works with different kind of C programs.