Advanced problems are marked in bold
2. Write the main program and the subroutine
in a single file. The
subroutine should contain an array of words: "new", "old",
"teacher", "professor", "programming",
"skip", "fail", "succeed", "complete",
"course", "difficult", "easy",
"hopeless", "great" and more, if you like to. This
subroutine should take an array of integers as parameter and return a sequence
of space-separated words in a single string according to the numbers in this array.
The main program should call subroutine dictionary several times with different (random) array length and content.
The main program should also print the results. Compile, link and run it.
3. The same as in 2 but put the subroutine in a separate file. Compile, link and run. Use optimization flag(s).
4. Generate a calendar for 2012 and write it
into a text file in the following format
Week 1 2 3 4 5 6
Mon 2 9 16 23 30
Tue 3 10 17 24 31
Wed 4 11 18 25
Thu 5 12 19 26
Fri 6 13 20 27
Sat 7 14 21 28
Sun 1 8 15 22 29
5. Create a program that will read the calendar from the file and
check if in 2012 we will have any Friday the 13th.
6. Download this
binary file consisting of 1024 floating point 8-byte long numbers (double
precision) grouped in 16 records of identical length. The file was produced by
a FORTRAN code. Open and read it. Print the numbers.
7. Download this
binary file consisting of 1024 4-byte integers. The file was produced by a
C code. Open and read it. Print the numbers. Remember that the platform used to
generate these data files may have different byte order from your computer.
8. Use the file
in the exercise 6. Subtract 1000000 from all the numbers in record 11 and write
it back into the same file. Close the file.
9. Repeat the
exercise 6 on the modified file but this time read record 11 only. Print its
Read and print the list of files in a current directory.
11. Create a program that will return the length of a given file.
the description text for this problem. Sort all the symbols (letters, spaces,
numbers, points etc.) in increasing order (space, 1-9, A-Z, a-z) and decreasing
order (z-a, Z-A, 9-1, space) and print the unique characters.
a personalized spam-distribution system. It should take a message from a file
and a table of names – emails from another a create
(but not send) a number of emails with polite intro e.g. Dear Sherlock Holmes, ... and associated commands to send these
15. Take the description text for this problem. Convert all the uppercase characters to low case and print. Compress the text (remove all spaces and tabs) and print.
a subroutine for Gauss elimination using arbitrary size matrix. Apply it to the
Write a subroutine for
finding real roots of quadratic equation: a*x2+b*x+c=0.
Keep track of special cases (e.g. when a=0).
In the main program create
100000 (or smaller) element arrays of different a, b and c. For all possible combinations of a, b and c, call the subroutine from
18 and find the minimum and the maximum root value. Try different sequence of
nested loops (a-loop is fastest, b-loop is fastest, c-loop is fastest) and note the execution time difference
(Linux/Mac OS X users can use time command). Do you see
execution time difference, why? Remove the evaluation of the maximum/minimum
and the printing part. Use the fasted optimization and note the execution time.
Can you think of ways to speed up this exercise dramatically?
Write a random number generator that will take a seed number
(floating point) and the length of the random sequence and return uniformly
distributed random numbers between 0 and 1. Use web to find simple algorithms
for generating random numbers.
Compute analytical and numerical 2nd derivatives of a
cubic polynomial 0.001*x3-0.3*x2+2.*x-20
at x=107. How different are the results and why? Can you improve the
22. Write a subroutine for a box-car filtering in 2D. The parameters should be: a 2D array of type integer, its dimensions, the size of the fragment to be filtered (smaller or equal than full size) and the size of the filter in X and Y in pixels. Use this subroutine to filter a photo of yourself. Prepare the original, the filtered result (say for filter box 10x10) and the difference between the two.