Professional Documents
Culture Documents
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
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
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 }
1. n = 4 and k = 5
Answer: 32
2. n = 21 and k = 8
Answer: 609
Page 6 of 7
Name: Rollno:
K
R
O
W
H
G
U
RO
Page 7 of 7