Sunteți pe pagina 1din 3

Engineering Programming 100, Semester 1, 2009

1/ Choose the best representation for the following real life variables given the
example values [1 mark each, 5 marks in total].

a. Vehicle type (examples: Van, Car, Lorry)


b. Height in metres (examples: 1.82, 1.65, 0.99)
c. Number of rooms in a house (examples: 5, 8, 4)
d. House number (examples: 23, 2, 270)
e. Phone numbers (examples: 08 9266 2000, 03 6392 1001)

2/ State which of the following variable declaration statements is legal or illegal [1


mark each, 5 marks in total].

int vect_1[10];
unsigned char age?;
float int;
double area_of_ellipse;
float y = 4.5;

3/ State the result of the following operations given the variable types and their initial
values as indicated below [2 mark each, 6 marks in total].

int x = 24;
int a = 24;
int y = 20;
int b = 20;
int j;
float p;

a. j = a++ + --b;
b. j = x/2 + 4;
c. p = (float)(x + 3) / (y - 14);

4/ Write down the meaning of the following C statements [2 marks].

#define DIM 4
float occupy[DIM] = {23.0, 30.0, 15.2, 12.9};

5/ Write down the meaning of the following C statements [2 marks].

#define H 4
#define W 6
float range[H][W];

Page 2 of 4
Engineering Programming 100, Semester 1, 2009

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].

7/ Give the statement(s) to read from the keyboard, a floating point value called
density, followed by a char value called ans followed by a string value called
country_name [3 marks].

8/ What is printed by the following code? [4 marks].

float i;

for(i=1.5; i<=4.5; i+=0.5)


{
printf(“f\n”, i + 0.5);
}

9/ What is printed by the following code? [4 marks].

int i;
float r = 0.0;

while (r >= -1.8)


{
r -= 0.3;
i = r;
printf(“%d\n”, i);
}

10/ What is the output of the following C code for values of i of 3 and 5. [4 marks].

int i;
switch (i)
{
case 0: printf(“value is too small\n);
break;
case 1: case 2: case 3:
printf(“value about right\n);
break;
case 4: printf”value too high\n”);
break;
default: printf(“value illegal\n”);
break;
}

Page 3 of 4
Engineering Programming 100, Semester 1, 2009

11/ Given two integer variables x and y write C code to output to the screen the
values in ascending order. That is print out the lowest value followed by the highest
value [2 marks].

12/ You are having a circular swimming pool built in your rectangular garden and you
want to see how much space will be left over for lawn, patio etc. Write a complete C
program to read in three floating point values representing the width and length of the
garden and the radius of the swimming pool. Compute and output the area of the
garden remaining. The equation for the area of a circle is πr 2 [10 marks].

END OF TEST

Page 4 of 4

S-ar putea să vă placă și