Mid Sem
Mid Sem
2. If you compile and run the following code what should happen?
int f(int a){
if(!a){}
}
int main()
{
printf("%c\n", f(0) );
return 0;
}
4. You have to keep the weights of students (assume they are expressed as natural numbers only)
according to their roll numbers which are just incremental in nature. It should be done in such a
way that by knowing the roll number her weight can be retrieved and vice versa. What data type
can you go for?
(a) Hello
(b) World
(c) Mickey
(d) Syntax error
2
printf("%d", i);
return 0;
}
(a) 12
(b) 10
(c) 11
(d) Invalid Syntax
}
What will be the output?
(a) *000121*
(b) *0121*
(c) *000000121*
(d) *121*
printf("%d", a);
return 0;
}
(a) 60
(b) 12
(c) 012
(d) 10
3
char a = '012';
printf("%d", a);
return 0;
}
Hint : include <stdlib.h> to call rand() and use it as rand()%(max + 1); to get a number between 0
and max randomly.
Solution:
4
5
Q2. You are sending boxes through a channel in which each box is three dimensional. It is defined
by its length, width and height. The width and height of the channel is 100 cm and the length is
infinite. A box can be sent into a channel only if the height is less than the height of the channel
and width is less than the width of the channel. Find the volume of each box which can be
transported without any problem to the other end of the tunnel. If any conditions are not met print
condition <number> failed. The box can be rotated so that the new height, width would fit in the
channel.
Input format: The first line contains a single integer, denoting the number of boxes. Lines follow
with three integers on each separated by single spaces length, width and height which are length,
width and height in cm of the box.
Conditions:
1. 1<=n<=100
2. 1<=width,height<=100
Sample input:
3
12 151 333
15 10 12
4 12 121
Output:
Condition 2 failed
7380
5808
Solution:
6
7
Section C: Short Answer Type Questions [3x10=30 Marks]
Q1. Let N be a positive integer with distinct digits. Write an algorithm to find the largest two-digit
number formed by using the digits in N.
Examples:
Solution:
8
Q2. Draw a flow chart for the following problem:
A person wants to do a fixed deposit of an amount of Rs. X in a bank for N number of years. The
bank offers simple interest at the rate of R % per year (assume R is greater than 4). After every
year, the bank computes the interest obtained by the customer. Further, the bank reduces the
interest rate by 0.5% per year after every year with a lower bound of 4% per year. Also, every year
the bank offers the customer a bonus amount, which is the maximum of Rs. 2000 and 10 % of the
interest obtained in that year. The next year's principal amount is the sum of the principal amount
in the previous year, interest earned in the previous year, and the previous year's bonus amount.
Compute the total amount the customer gets after N years. Read X, N, and R from the user.
Solution:
9
Q3. Convert the following
(a) (12.2)8 to base 10
(b) (1010.01)2 to base 10
(c) (C1)16 to base 8
(d) A2B16 to base 2
10
Solution:
Rough Space
11