Академический Документы
Профессиональный Документы
Культура Документы
Class Test I
Date: 26.08.2015 Time: 7 8 PM
1(i). State which of the following (A, B, C, D) are valid variable names in C. B
(A) first&second (B) first_second (C) while (D) 1st2nd
Expression Value
3. 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.)
7
5. Let (x1, y1) and (x2, y2) be the co-ordinates of two given points. Write down a logical expression using the
variables x1, y1, x2, y2, which is TRUE when both the points lie in the same quadrant of the co-ordinate
system. Assume that none of the points lie on the co-ordinate axes. A short expression is preferred.
6. Given, a = 20, b = 15, c = 10, and x = 1, z = 2, before the following nested-if statement is executed. What are
the values of x and z after the nested-if statement is executed.
x=1
if (a<b) x=a; else if (b>c) if (c>a) z=a; else z=b; else x=b;
int sum = 0;
int i = 0;
while (i < 5)
{
sum = sum + i;
i++;
}
printf(%d\n,sum);
Suppose we replace the while loop in the segment above with a for loop. Which of the following for loops will result
in the same value of sum printing out?
int x=0;
for(int i=0; i<3; i++) { 8
for( int j=i; j<3; j++) {
x = x + j;
}
}
printf(%d,x);
9. What is the output of the following program segment:
Num = 3, x = 30
int num = 1, x = 10;
do
{
x += 10;
num ++;
}
while (num == 2);
printf("Num = %d, x = %d", num, x);
char letter;
switch (letter)
}
Rough Work