You are on page 1of 7

Total Points 20 Pages: 7

CS101: Introduction to Computers(Quiz 1)

September 12, 2016

Instructions Question Points Score


1. Read these instructions carefully. 1 7
2. Write you name and roll number on all the 2 6
pages of the answer book.
3 7
3. Write the answers cleanly in the space provided.
There is space left after every question for rough Total: 20
work.
4. Do not exchange question books or change the
seat after obtaining question paper.
5. Use pens (blue/black ink) and not pencils. Do
not use red pens for answering.
6. Even if no answers are written, the answer book
has to be returned back with name and roll
1
number written.
0
S1
C

Page 1 of 7
Name: Rollno:
Question 1. (7 points) For each of the program snippets below, what is the value printed by printf?
(If the snippet contains error, say Error).

1. printf("%0.2f", 3.14*10*10);
314.00

2. printf("%d", 14%(35/10));
2

3. printf("%0.2f", 4.4*1*1/4);
1.10

4. printf("%c", ’7’ + 5 - ’4’);


character having ascii value 8 (which is backspace)

5. printf("%d", (1 < 1) < (0 < 0));


0

int x;
6. x = -5 || -6;
printf("%d", 0 >= x);

0
int num = ’z’ - ’a’;
7. char ch = 25;
printf("%d", num == ch);
1

Page 2 of 7
Name: Rollno:

K
R
O
W
H
G
U
RO

Page 3 of 7
Name: Rollno:
Question 2. (6 points) For each of the program snippets below, what is the value printed by printf? (If
the snippet contains error, say Error).

1. printf("%d", 2/4==5/10==1/2);
0

int x;
2. x = -6 || 0;
printf("%d", x < 0);

0
int num = ’B’ - ’A’ + 99;
3. char ch = 101;
printf("%d", num > ch);
0
float num = 17;
4. num = (int)(num/3.0);
printf("%0.1f", num );
5.0
int items = 10.0, price = 75.0;
5. float avg price = price/items;
printf("%.3f", avg price);
7.000

6. printf("%c == %c", ’Z’ - ’z’ + ’y’,


’a’ - ’A’ + ’B’);
Y == b

Page 4 of 7
Name: Rollno:

K
R
O
W
H
G
U
RO

Page 5 of 7
Name: Rollno:
Question 3. (7 points) Consider the program given below.
1 # include < stdio .h >
2
3 int main () {
4 int i , n , k , sum ;
5 scanf ("% d " , & n ) ;
6 scanf ("% d " , & k ) ;
7
8 i = 0;
9 sum = 0;
10
11 while (i < n ) {
12 if ( k %2 != 0) {
13 sum = sum + k ;
14 i = i +1;
15 }
16 k = k +1;
17 }
18
19 printf ("% d " , sum ) ;
20
21 return 0;
22 }

What is the output of the program when

1. n = 4 and k = 5
Answer: 32

2. n = 21 and k = 8
Answer: 609

What does the above program do? Describe in one sentence.


Answer: Computes the sum of n odd numbers from a starting number k

Page 6 of 7
Name: Rollno:

K
R
O
W
H
G
U
RO

Page 7 of 7

You might also like