Beruflich Dokumente
Kultur Dokumente
1/ Choose the best representation for the following real life variables [1 mark each, 5
marks in total].
float a, b = 3; legal
double SIZE; legal
long int next2you; legal
int second-life; illegal
unsigned short x!; illegal
3/ State the result of the following operations where the variable types and their initial
values are stated below [2 marks each, 6 marks in total].
int x = 24;
int y = 20;
int j;
float p;
a. ++x; 25
b. j = x/3 + 9; 17
c. p = (x * 2 + 40) / (y * 3 – 16); 2.0
Note doesn’t matter whether the value of x from a.
is used (25) instead of 24 – same results.
4/ Write down the C statement to declare an array to contain the height in metres for
50 people [2 marks].
5/ Write down the C statement to declare an array to represent an image or 320 by 240
values where each value varies from 0 to 255 in increments of 1 [2 marks].
Penalise lack of unsigned, use of int or having the 240 and 320 swapped over.
6/ Give the statement(s) to output to the screen, a double precision variable called
speed, followed by an integer called count, followed a character called found [3
marks].
Page 1 of 4
Engineering Programming 100, Semester 1, 2008
7/ Give the statement(s) to read from the keyboard, an integer called house_number,
followed by a string called street_name, followed by a long integer called
phone_number [3 marks].
int i;
42
37
32
27
22 (one number per line of course).
int i;
float r = 0.0;
do
{
r += 0.3;
i = r;
printf(“%d\n”, i);
}
while (r < 1.8);
0.3
0.6
0.9
1.2
1.5
1.8
10/ Explain why it is a bad idea to use the following if statement when the variable
mass is a floating point number [2 marks].
if(speed == 0.0)
Answer should mention that you can’t represent floating point numbers accurately so
shouldn’t do direct comparisons in an if clause. Should use a tolerance value e.g.
if((speed <= tolerance) && (speed >= -tolerance)).
Page 2 of 4
Engineering Programming 100, Semester 1, 2008
11/ Write an if then else statement to output the grade ‘F’ when the integer variable
mark is 0, 1, 2, 3 or 4, and output the grade ‘P’ when the value of mark is 5, 6, 7, 8,
9 or 10. [4 marks].
Other solutions are possible and reward if they are reasonable (switch statement, one
if statement per mark etc.).
12/ Write a complete C program to read in two floating point numbers from the
keyboard and print them out in descending order. That is, if the values are 12.5 and
11.7, the output would be 12.5 followed by 11.7 [10 marks]
#include <stdio.h>
if(x <= y
printf(“%f %f\n”, y, x);
else
printf(“%f %f\n”, x, y);
}
END OF TEST
Page 3 of 4