Академический Документы
Профессиональный Документы
Культура Документы
Pages: 7
Question
Points
Total:
20
S1
0
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.
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.
4.
5.
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
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
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
Page 6 of 7
Rollno:
Rollno:
RO
U
G
H
W
O
Name:
Page 7 of 7