0% found this document useful (0 votes)
100 views4 pages

CS11001: Programming and Data Structures Class Test I

The document contains a 10 question class test on programming and data structures. It includes questions that test knowledge of variable naming rules, output of code segments, evaluating expressions, use of loops and conditional statements, and rewriting code using different structures like switch statements. The test is out of a total of 20 marks and students are asked to write their answers in the boxes provided.

Uploaded by

aarush khatri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views4 pages

CS11001: Programming and Data Structures Class Test I

The document contains a 10 question class test on programming and data structures. It includes questions that test knowledge of variable naming rules, output of code segments, evaluating expressions, use of loops and conditional statements, and rewriting code using different structures like switch statements. The test is out of a total of 20 marks and students are asked to write their answers in the boxes provided.

Uploaded by

aarush khatri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Total Marks (10 x 2):

CS11001: Programming and Data Structures

Class Test I
Date: 26.08.2015 Time: 7 8 PM

Answer All Questions. Write your answers in the boxes provided.

Section: Roll: Name:

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

(ii). Write the output of the following code segments


int X= 2, Y = 5;
2
(X > Y) ? printf(%d, Y) : printf(%d, X);

2. What are the values of the following expressions?

Expression Value

3.0/6 + 18/(15%4+2) 3.5


24/(1 + 2%3 + 4/5 + 6 + 31%8) 1

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

Given: int sum = 7; float costing;


C
(A) (float) costing = sum / 3; (B) costing = (float) (sum / 3);

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

4. What is the output of the program segment:


5
int i=3;
printf( "%d\n", (--i + 3) ); 12
printf( "%d\n", (i++ + 10) );
printf( "%d\n", ++i );
i += i;
4
printf( "%d\n", i-- );
printf( "%d\n", i ); 8

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.

((X1 * X2 > 0) && (Y1 * Y2 > 0)) (alternates are possible)

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;

7. Consider the program segment:


z = 15

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?

A. for (int i = 0; i <= 5; i++) C


sum = sum + i;
B. for (int i = 1; i <= 5; i++)
sum = sum + i;
C. for (int i = 1; i < 5; i++)
sum = sum + i;
D. for (int i = 2; i < 5; i++)
sum = sum + i;
E. for (int i = 1; i < 6; i++)
sum = sum + i;

8. What is the output of the program segment:

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);

10. Rewrite the following statement using a switch statement.


if( letter == 'X' )
sum = 0;
else if ( letter == 'Z' )
valid_flag = 1;
else if( letter == 'A' )
sum = 1;
else
printf("Unknown letter -->%c\n", letter );

char letter;

switch (letter)

case X : sum = 0; break;

case Z : valid_flag = 1; break;

case A : sum = 1; break;

default : printf(Unknown letter %c \n, letter);

}
Rough Work

You might also like