Anda di halaman 1dari 6

1/29/2017 Unit|ONLINEQUIZ[JAN29,2017]|CSF111Courseware|Edge

BITSx: CSF111 Computer Programming Help

ONLINE QUIZ 1 [JAN 29, 2017, 9 AM to 9 PM] > ONLINE QUIZ [JAN 29, 2017] > Unit

Bookmarks
Unit
Bookmark this page
ONLINE QUIZ
1 [JAN 29,
2017, 9 AM to Online Quiz 1 [Sunday 9 AM to 9 PM]
9 PM] 1.5 points possible (graded)
You will be allowed to submit your answers only ones. So, follow these
ONLINE QUIZ steps strictly:
[JAN 29, 2017]
Online Quizzes due 1. First, attempt all the questions.
Jan 29, 2017 21:00
IST
2. Ones you are ready to submit, click on "Final Check" button. Please
note that once you will click on "Final check" button, your answers will be
Introduction to uploaded and you will not get any other chance.
the course
3. THERE MAY BE MULTIPLE OPTIONS CORRECT FOR EACH QUESTION.
You have to select all the correct options to get it right.
Week 1

4. Consider this Quiz as a self test for yourself and your own
Week 2 understanding. Treat it as a mirror for your own understanding of the
contents. PLEASE DON'T CHEAT YOURSELF.
Week 3
Q1. Consider an 8-bit machine M which uses 2's complement binary
number representation. Suppose that three binary numbers stored in
this machine are A = 1101 1001, B = 0101 0101, D = 1010 1000. For this
machine, nd the value of C if:
A+B-C=D

1000 0111

1000 0110

1101 0110

None of the options given here

https://edge.edx.org/courses/coursev1:BITSx+CSF111+2017_T2/courseware/4ce1bc9240134c909acd77d6bcf60fc1/f84604e5a47d40018e9a0fcd25c9f3ca/ 1/6
1/29/2017 Unit|ONLINEQUIZ[JAN29,2017]|CSF111Courseware|Edge

Q2. Consider an 8-bit machine M which uses 2's complement binary


number representation. Suppose that three binary numbers stored in
this machine are A = 1111 1011, B = 1111 0111, D = 1111 0011. What is
the value of C if:
A+B-C=D

C = -1 in decimal number representation

C = FF in 8-bit hexa-decimal, 2's complement number


representation

C = FFFF in 16-bit hexa-decimal, 2's complement number


representation

C = 777 in 9-bit octal, 2's complement number representation.

Q3. Consider the following program fragment. Which statement can


replace CONDITION for the program to print SUCCESS.
void main()
{
int a = 5;
if (CONDITION)
printf ("SUCCESS");
}

a == 5

a=5

a++ == 5

++a == 5

https://edge.edx.org/courses/coursev1:BITSx+CSF111+2017_T2/courseware/4ce1bc9240134c909acd77d6bcf60fc1/f84604e5a47d40018e9a0fcd25c9f3ca/ 2/6
1/29/2017 Unit|ONLINEQUIZ[JAN29,2017]|CSF111Courseware|Edge

Q4. Consider the following program fragment. Which statement can


replace CONDITION for the program to print b = 1
void main()
{
int a = 5, b = 0;
if (CONDITION)
printf ("b = %d", b);
}

(a == 5) || (++b)

(a == 5) && (++b)

(++b) && (a == 5)

(++b) || (a == 5)

Q5. Suppose grades in a subject are decided as follows:


Grade = A if percentage >= 80
Grade = B if percentage >= 60
Grade = C if percentage >= 40
Grade = D if percentage >= 0
A programmer has written following code for it:
void main()
{
oat per;
scanf ("%f", &per);
if (per >= 0)
printf ("D");
if (per >= 40)
printf ("C");
if (per >= 60)
printf ("B");
if (per >= 80)
printf ("A");
}
First see and ensure yourself that the above code will not work.
Now, what changes should be done to make the code work. Here you
can assume that variable per will always hold a value between 0 and
100.

https://edge.edx.org/courses/coursev1:BITSx+CSF111+2017_T2/courseware/4ce1bc9240134c909acd77d6bcf60fc1/f84604e5a47d40018e9a0fcd25c9f3ca/ 3/6
1/29/2017 Unit|ONLINEQUIZ[JAN29,2017]|CSF111Courseware|Edge

change all the occurrences of "if" keyword (except the rst one,
i.e. if (per >= 0)) with "else if".

Change the sequence of if statements as follows:


if (per >= 80)
printf ("A");
if (per >= 60)
printf ("B");
if (per >= 40)
printf ("C");
if (per >= 0)
printf ("D");

Change the sequence of if statements as follows:


if (per >= 80)
printf ("A");
else if (per >= 60)
printf ("B");
else if (per >= 40)
printf ("C");
else if (per >= 0)
printf ("D");

None of the options given here.

Q6. Suppose grades in a subject are decided as follows:


Grade = A if percentage >= 80
Grade = B if percentage >= 60
Grade = C if percentage >= 40
Grade = D if percentage >= 0
A programmer has written following code for it:

void main()
{
oat per;
scanf ("%f", &per);
switch (per)
{
case (per >= 80):
printf ("A");

https://edge.edx.org/courses/coursev1:BITSx+CSF111+2017_T2/courseware/4ce1bc9240134c909acd77d6bcf60fc1/f84604e5a47d40018e9a0fcd25c9f3ca/ 4/6
1/29/2017 Unit|ONLINEQUIZ[JAN29,2017]|CSF111Courseware|Edge

break;
case (per >= 60):
printf ("B");
break;
case (per >= 40):
printf ("C");
break;
case (per >= 0):
printf ("D");
break;
}
}
First see and ensure yourself that the above code will not work. Now,
why this code will not work?
[Note: you should always remember these reasons. Also, it will be a
good programming practice to try writing program for the given
problem using switch case statements.]

In the statement "switch (per)", variable "per" cannot be of oat


type.

You cannot use statement like "per >= 80" within case statement.

You cannot use multiple break statements within one switch


block.

Since each case statement has two statements (printf and break),
you should use curly braces here to group them together.

Q7. If the desired output of the following program is "c = -5", which of
the following options can replace "stmt1" in the following code segment?
int main()
{
int a = 5, b = 7;
int c;
//stmt1
printf ("c = %d",c);
}

https://edge.edx.org/courses/coursev1:BITSx+CSF111+2017_T2/courseware/4ce1bc9240134c909acd77d6bcf60fc1/f84604e5a47d40018e9a0fcd25c9f3ca/ 5/6
1/29/2017 Unit|ONLINEQUIZ[JAN29,2017]|CSF111Courseware|Edge

c = a * b % a / b - a;

c = b * a % a / b - a;

c = b * a % b / a - a;

c = a / b % a / b - a;

Q8. What is the output of following program:


void main()
{
short int num;
num = 32768;
printf ("num = %d", num);
num = num + 1;
printf (" now num = %d", num);
}
[Note: First try to get the output yourself, then check your output using
gcc compiler. Understand what is happening:)]

num = 32768 now num = 32769

num = -32768 now num = -32767

num = 0 now num = 1

num = 32768 now num = -32768

Submit You have used 0 of 1 attempt

All Rights Reserved

https://edge.edx.org/courses/coursev1:BITSx+CSF111+2017_T2/courseware/4ce1bc9240134c909acd77d6bcf60fc1/f84604e5a47d40018e9a0fcd25c9f3ca/ 6/6

Anda mungkin juga menyukai