
CS 2073 Review for Midterm 2
Basic knowledge
Use #include files.
Use #define to define a constant.
Declare an array (any type, any size).
Random Number Generator
Seed using srand()
Call rand_float(a.b) to return a double in the range [a,b)
Write rand_float() in advance and bring it to the test on your diskette.
Numerical arrays
Compute a numerical value expressed in summation notation. Examples:
or
Strings and character arrays
Use strlen(), strncmp(), and strncpy()
Process or analyze a character string. Examples:
How many vowels are in the string?
Print the string in reverse order.
Is the string a palindrome (eg., noon, mom, dad, 1441)?
Sorting
Sort an array of any type.
Write the sorting functions in advance and bring them to the test on your diskette.
Sample question:
Write the program described below. Do all work on the hard drive. When you are done, copy only the source
code (’C’code) onto your diskette and turn it in. Be sure your diskette is labeled.
Program: reverse.c
1. Include files <stdio.h>, <stdlib.h>, and <string.h>
2. Use a #define statement to define the constant MAXLINE to be 256.
3. Declare 2 character arrays, each of size MAXLINE.
4. Read in a character string from the keyboard into one array.
5. Reverse the string, saving it in the second array. Print the reversed string.
6. Compare the original and reversed strings to see if it is a palindrome, ie., the same forwards and backwards.