C Programming

Practise Exercise 2: Assignments

1. The statement which correctly assigns the value of the variable number1 to the variable total, is

total := number1;
number1 = total;
total = number1;
number1 := total;

2. The statement that correctly assigns the sum of the two variables loop_count and petrol_cost to the variable sum, is

loop_count = sum + petrol_cost;
petrol_cost = sum - loop_count;
sum = petrol_cost / loop_count;
sum = loop_count + petrol_cost;

3. The correct statement which divides the variable total by the value 10 and leaves the result in the variable discount, is

discount = total / 10;
discount = 10 / total;
total = discount / 10;
total = 10 / discount;

4. The correct statement which assigns the character W to the char variable letter, is

letter = "W";
letter = 'W';
char letter = "W";
strcpy( letter, "W" );

5. The correct statement which assign the decimal result of dividing the integer variable sum by 3 into the float variable costing, is ( Use type casting to ensure that floating point division is performed)

Given: int sum = 7; float costing;

(float) costing = sum / 3;
costing = (float) (sum / 3);
costing = (float) sum / 3;
costing = float ( sum / 3 );


©Copyright B Brown. 1984-1999. All rights reserved.