0% found this document useful (0 votes)
32 views11 pages

Mid Sem

The document is a mid-semester exam for a computer programming course. It contains multiple choice questions, coding questions, and short answer questions. The multiple choice section has 10 questions covering topics like bitwise operators, data types, control flow, and I/O functions. The coding questions involve generating a random histogram and checking box dimensions for transport through a channel. The short answer questions are an algorithm to find the largest two-digit number from digits in a number, a flowchart for a fixed deposit problem, and conversions between number bases.

Uploaded by

VISHNU SUDHAN H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views11 pages

Mid Sem

The document is a mid-semester exam for a computer programming course. It contains multiple choice questions, coding questions, and short answer questions. The multiple choice section has 10 questions covering topics like bitwise operators, data types, control flow, and I/O functions. The coding questions involve generating a random histogram and checking box dimensions for transport through a channel. The short answer questions are an algorithm to find the largest two-digit number from digits in a number, a flowchart for a fixed deposit problem, and conversions between number bases.

Uploaded by

VISHNU SUDHAN H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

BITS PILANI, Hyderabad Campus

Mid Semester Examination Second Semester 2021-22


Computer Programming (CS F111) Date: 04-May-2022
Time: 90min Weightage: 35% Mode: Open Book
Name: __________________________ Roll No.: ____________________
Section A: Multiple choice questions [2x10=20 Marks]

1. int a=8, b=6;


printf("%d\n", (a|(b>>2))&(b|(a<<2)) );
This code snippet will print:

(a) 0 (b) 1 (c) 2 (d) 4

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

(a) It should not compile


(b) It should compile with warning and then print (null)
(c) No error or warning but it will run and print nothing.
(d) No error or warning but it will run and print W

3. Which of the following statements is/are incorrect?


A. General purpose registers cannot be accessed with C
B. Enum cannot be used for inverse mapping of multiple string data
C. One needs to call system headers even if she calls a custom header that calls system headers

(a) A. (b) A,B (c) B,C (d) A,B,C

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) integer array


1
(b) enum
(c) any of a and b can be used
(d) there is no way to meet all requirements.

5. The following code should return?


#include <stdio.h>
#include <limits.h>

float sum(float a,float r){


int counter=0;
float sum=a;
while((counter++)<INT_MAX)
sum+=a=a*r;
return sum;
}
int main()
{
float a=4,r=0.5;
printf("%f\n", sum(a,r));
return 0;
}

(a) 5 (b) 8 (c) 10 (d) 7

6. Find the output


int i = 11;
switch (i) {
case 013: printf("Hello");
break;
case 011: printf("World");
break;
default: printf("Mickey");}

(a) Hello
(b) World
(c) Mickey
(d) Syntax error

7. What output would the following code print


#include <stdio.h>
int main()
{
int i;
i = 12, 10, 11;

2
printf("%d", i);
return 0;
}

(a) 12
(b) 10
(c) 11
(d) Invalid Syntax

8. What output would the following code print


#include <stdio.h> 1
int main()
{
int a=121;
printf("*%06d*",a);

}
What will be the output?

(a) *000121*
(b) *0121*
(c) *000000121*
(d) *121*

9. What output would the following code print


#include <stdio.h>
int main()
{
char a = 012;

printf("%d", a);

return 0;
}

(a) 60
(b) 12
(c) 012
(d) 10

10. What output would the following code print


#include <stdio.h>
int main()
{

3
char a = '012';

printf("%d", a);

return 0;
}

(a) Compile error


(b) Print nothing
(c) 12
(d) 10

Put a tick in the proper box:


1 2 3 4 5 6 7 8 9 10

Section B: Coding Question [2x20=40 Marks]


Q1. Generate a random histogram with 0 to max ranged numbers over n entries, max and n should
be taken from users (restrict them to 40 and 60 respectively). Print the histogram with stars and
zero should print 1 star and 1 should print 2 and so on. A demo run is as follows:

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:

If N=253816, the largest two-digit number is 86.

If N=42687913, the largest two-digit number is 98.

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

You might also like