Sie sind auf Seite 1von 7

Total Points 20

Pages: 7

CS101: Introduction to Computers(Quiz 1)


September 12, 2016
Instructions

Question

Points

1. Read these instructions carefully.

2. Write you name and roll number on all the


pages of the answer book.

Total:

20

3. Write the answers cleanly in the space provided.


There is space left after every question for rough
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.

S1
0

6. Even if no answers are written, the answer book


has to be returned back with name and roll
number written.

Page 1 of 7

Score

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

5.

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


0

6.

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

7.

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

Page 2 of 7

Rollno:

RO
U

G
H

W
O

Name:

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

2.

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

0
3.

int num = B - A + 99;


char ch = 101;
printf("%d", num > ch);
0

4.

float num = 17;


num = (int)(num/3.0);
printf("%0.1f", num );
5.0

5.

int items = 10.0, price = 75.0;


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

Rollno:

RO
U

G
H

W
O

Name:

Page 5 of 7

Name:
Question 3. (7 points) Consider the program given below.
1

# include < stdio .h >

2
3
4
5
6

int main () {
int i , n , k , sum ;
scanf ("% d " , & n ) ;
scanf ("% d " , & k ) ;

i = 0;
sum = 0;

8
9
10

while (i < n ) {
if ( k %2 != 0) {
sum = sum + k ;
i = i +1;
}
k = k +1;
}

11
12
13
14
15
16
17
18

printf ("% d " , sum ) ;

19
20

return 0;

21
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

Rollno:

Rollno:

RO
U

G
H

W
O

Name:

Page 7 of 7

Das könnte Ihnen auch gefallen