You are on page 1of 2

University of Computer Studies, Mandalay

2015-16 Academic Year


Final Examination Question Format (CST-104)
Time Allowed-3 hours

Answers all questions.


1. Identify and correct the errors in each of the following statements. (Note: There may be
more than one error per statement.)(3mks)
(a) if ( x = y );
printf( %d is equal to %d\n", x, y );
(b) While ( x <= 100 )
total += x;
++x;
(c) Assume int b[ 10 ] = { 0 }, i;
for ( i = 0; i <= 10; ++i ) {
b[ i ] = 1;}
2. (a) Write a program that writes your name on the monitor ten times. Write this program three
times, once with each looping method.(4mks)
(b) Write a program that will count from 1 to 100 and print only those values between 32 and
39, one to a line. (4mks)
(c)Define a character array and use "strcpy" to copy a string into it. Print the string out by
using a loop with a pointer to print out one character at a time. Initialize the pointer to the first
element and use the double plus sign to increment the pointer. Use a separate integer variable to
count the characters to print. (4mks)
3. (a) Write a recursive function recursive Minimum that takes an integer array and the array size
as arguments and returns the smallest element of the array. The function should stop processing
and return when it receives an array of one element. (5mks)
(b) Write a program that uses function "strcmp" to compare two strings input by the user. The
program should state whether the first string is less than, equal to or greater than the second
string. (5mks)
(c) Write a function distance that calculates the distance between
two points (x1, y1) and (x2, y2). All numbers and return values should be of type double. (5mks)
4. Write a program that uses looping to print the following table of values.
Use the tab escape sequence, \t, in the printf statement to separate the columns with tabs.
(10mks)

N
1
2
3
4
5
6
7
8
9
10

10*N
10
20
30
40
50
60
70
80
90
100

100*N
100
200
300
400
500
600
700
800
900
1000

1000*N
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000

5. Modify the program of Fig. 6.18 to use a recursive linearSearch function


to perform the linear search of the array. The function should receive an integer array, the size of
the array and the search key as arguments. If the search key is found, return the array subscript;
otherwise,
return 1. (15mks)
6. Write a program that inputs four strings that represent integers, converts the strings to integers,
sums the values and prints the total of the four values. (15mks)
7. Write a program that use only uppercase letters in enumeration constant names and print the
number of months of year. (15mks)
8. Write statements that accomplish each of the following. Assume that the structure
struct person {
char lastName[ 15 ];
char firstName[ 15 ];
char age[ 4 ];
};
has been defined and that the file is already open for writing.
a) Initialize the file "nameage.dat" so that there are 100 records with lastName = "unassigned",
firstname = "" and age = "0".
b) Input 10 last names, first names and ages, and write them to the file.
c) Update a record; if theres no information in the record, tell the user "No info". (15mks)