You are on page 1of 7

A) Programming Problems (50 points)

) pg ( 50 m)
1.

Given an integer N (0<N<=10000), write a program / pseudo code that counts the number of
integers from 0 to N that are divisible by 2 and 7 but not by 3.
[8]

(e N ( 0< N<=10000 ) 0 N e

2 e 7 n 3
e program / pseudocode )
2. Given a string of length at most 100 containing only English alphabetic characters, write a
program / pseudo code to find out how many vowels are there.

[8]

( t i c 100 ak e b

e s e program / pseudocode )
3. Write a program / pseudo code to calculate the Greatest Common Divisor (GCD) of three
integers A, B & C (0<A,B,C<=100).
[9]
( A,B o C ( 0 < A,B,C <= 100 )

(,, ,) e program /

pseudocode )

4. Given a list of 10 integers, write a program / pseudo code to arrange the integers in ascending
order.

[10]

( 10 e

e program / pseudocode )
5.

Look at the following C code:


int i, n=42;
main() { for(i=0; i<n; i --) { printf("?"); } }
Modify the program so that it prints 42 ? characters in a line.
You are only permitted to make EXACTLY ONE of these modifications to the code: 1) Add one
character to the code. 2) Delete one character from the code. 3) Replace one character in the code
by a different one.
There are three solutions to this problem. You get 5 points for each solution.
[15]
[Hint 1: for(i=1;i<=10;i++) { printf(?); } <- This code prints 10 ? characters ]
[Hint 2: The C shorthand i++ is equivalent to i = i + 1. Similarly , i-- stands for i = i 1 ]

( e C code , k :
int i, n=42;
main() { for(i=0; i<n; i --) { printf("?"); } }

e ei i 42 "?"
t e ak //

[t 1: for(i=1;i<=10;i++) { printf(?); } <- ei ? ak 10
]
[t 2: C i++ a i = i + 1 e i-- a i = i 1 ]

B) Mathematical problems & Brainteasers (50 points)

) o ( 50 m)
1. There are n hosts in a party. Each host brings his wife. There are m guests. Each host shakes hands
with the guests, and other hosts' wives; every hosts wife shakes hands with everyone, except her
own spouse, and every guest shakes hands with everyone else. How many hand shakes happen?
[1.5]
(n e a pi st e
a m a p nt a e
nt st p nt st s
a p ei a
?)
2.

There are 14 students in a class, and some pairs are marked as disturbing pairs, as, when they are
together, they make the most nuisances. Each student is marked by the characters from A to N,
and the line between a pair denotes, if the pair is marked as disturbing pair
(e k 14 t e e e i k
i e
, e t A N n
ak i t e k
e )

Can you divide them into two groups, so that no group contains any disturbing pair? If not
possible, can you omit some of the students and divide? What is the minimum number of students
to omit if you want a successful divide? Show a group formation.
[3]
( e e i i i
m ?
? e i o )
3.

What is the last digit of 1234567^1234567?


(1234567 ^ 1234567 -e a ? )

[2.5]

4.

Mathematical induction is a method of mathematical proof. To prove some statement, first step
is to show that the statement is true for some small value. Then, the next step is to show that, if the
statement is true for some integral value n, it is also true for (n+1).
See the following inductive proof:
We are trying to prove that, for any integer n >= 0, 10n = 0.
We start by, when n = 0, 10n = 10 * 0 = 0. So, the claim is true for n = 0.
Now, suppose that n > 0, and n = a + b, where a and b are two integers. By induction hypothesis,
10a = 0, 10b = 0, so, 10n = 10 (a + b) = 10a + 10b = 0.
So, by induction, we can prove that, for all n >= 0, 10n = 0.
What's wrong with the proof?
[1.5]
(tt n p e d d
e pj p p e
n e n+1 e o
d p :
p i , n>=0 e 10n=0
i n=0 ,10n = 10*0 = 0 i n=0 e pj
e , n>0 e n=a+b a,b a 10a = 0, 10b=0,
i 10n=10(a+b)=10a+10b=0.
i d p n>=0, 10n=0
e ?)

5.

Using only the digits 0, 1, 2 and 7, how many 7 digit numbers can be created, which are divisible
by 11. The number can not have leading zero. So, numbers like 000011 are not allowed.

[Hint: divisibility by 11 can be done, by summing the digits at the odd positions and even
positions. If the difference of the sums is divisible by 11, then the number is also divisible. For
example: if the number if 1939982, the odd positional digits of 1939982, are 1, 3, 9 and 2, which
sum to 1+3+9+2 = 15. On the other hand, even positional digits are 9, 9 and 8, which sum to
9+9+8=26. The difference is 26-15 = 11, which is divisible by 11. So, the number 1939982 is also
divisible by 11, and you can see that 1939982 = 176362 * 11.]
[2.5]
( t 0,1,2,7 a 11 d a
m ?

( : 0000011)

[t 11 i k e as a

11 d 11

o 11 , 1939982 e kt
as a

1+3+9+2=15 e as a

9+9+8=26

d 26-15=11, 11 d i 1939982 o 11 d
o i, 1939982=176362*11 ] )
6.

What is the Least Common Multiple (LCM) of all numbers between 1 and 20?
(1 20 n (.. .) ?)

[1.5]

7.

How many ways, can you form k groups, from n similar objects, so that, each group has at least
one object?
[2.5]
(n ei s k p an
e s ?)

8.

In a box there are 23 red balls, 53 green balls and 76 blue balls. You cant see inside the box. So
when you pick up you dont know which color you are picking up. In the worst case how many
balls should you pick up to ensure that you got all three color balls?
[1.5]
(e k 23 , 53 e 76 k
i i e i m
c o p
an e ?)

9.

A dumb (speechless person) went to a shop. He wanted to buy a shirt. But as he cant speak so he
was thinking how to express his desire. When the shopkeeper came he made him understand that
he cant speak. The salesman offered pen and pencil, he wrote down and the salesman showed him
various kinds of shirts and finally he chose one and bought it. Next came a crippled person who
cant move his hand. Now how can he express his desire in the best way? Remember he cant
write like the first person.
[1]
(e k ak
p i , i i
k m ,
n e
n e e i
p ? i n k
p )

10.

You are given four 4 s. You can construct a number with these four 4s using addition, subtraction,
multiplication, division, parentheses and concatenation of two or more fours.
For example using four 4 s you can express 28 like: 44 - 4*4.
Again you can also express 64 like: (4+4)*(4+4).
How many consecutive numbers starting from 1 can you express in this way? Note that, if you can
express numbers from 1 to 10. Then you get 10 numbers. If you can express till 12 then 12
numbers. But if you could express from 1 to15 but make a mistake at expressing 5 then you get
only 4 numbers (that is from 1 to 4), expressing 6 to 15 correctly doesnt give you any point. So be
careful! One more thing, you need to write the expressions for every number you manage to
construct. The more you can make, the more points you get. :)
[5]
( 4 4 , , ,
a 28 e : 44
4*4
, 64 e : (4+4)*(4+4)
e

e e ? k , e

n , n e
e , e n
, n o ,
m n
m )
11.

xy = 3576 where x and y are integer. How many solutions are there for (x,y) ?
(xy = 3576 e x e y ,

12.

[1.5]

m?)

Consider the following series:


(1), (1 1), (2 1), (1 2 1 1), (1 2 3 1), (1 3 1 2 2 1), ..
Can you guess the immediate next term of this series?

[4]

(k ?
(1), (1 1), (2 1), (1 2 1 1), (1 2 3 1), (1 3 1 2 2 1), .. )
13.

Four men are on one side of a bridge on a dark night. The bridge is only strong enough to support
two men at a time. It is also necessary for the men crossing the bridge to carry a lantern to guide
their way, and the four men have only one lantern between them. Reffat can cross the bridge in 1
minute, Mobin in 2, Afnan in 5, and Murshed in ten minutes. How quickly can all four men be
together at the other side?
[3.5]
( e an ei

c i , e an e
p uk k t e
, 1 , 2 , 5 , e
10 a m
?)

14.

How many people must be at a party before you have at least 50% probability of two having the
same birthday (not necessarily the same year, of course)?
[3.5]

( a an i
n ei o m 50% ? )
15. Start with a half cup of tea and a half cup of coffee. Take one tablespoon of the tea and mix it in
with the coffee. Take one tablespoon of this mixture and mix it back in with the tea. Which of the
two cups contains more of its original contents?
[2.5]

(ei e , a o e
e o , , e
o p , ? )
16.

A customer at a 7-11 store selected four items to buy, and was told that the cost was
$7.11.
He was curious that the cost was the same as the store name, so he inquired as to how the figure
was derived. The clerk said that he had simply multiplied the prices of the four individual items.
The customer protested that the four prices should have been ADDED, not MULTIPLIED. The
clerk said that that was OK with him, but, the result was still the same: exactly $7.11.
What were the prices of the four items?
[2.5]
(e k 7-11 e ,

o 7.11 , e ai e
oi k a , e e
, oi
,

, ei k

, n i

, o ei c oi ? )
17.

What is the next number of the following series?


0, 1, 2, 4, 7, 12, 20, 33, .

[2.5]

( k ?
0, 1, 2, 4, 7, 12, 20, 33, .
18.

Draw a quadrilateral whose diagonals do not cross with each other.


(e e a , d s )

19. Look at the following pseudo code


For i = 1 to 10
{
For j = 2 to 6
{
Write X

[2.5]

}
Write newline
}
What is the output of this program?
[2.5]
[Hint: Write X Writes the character X in screen while Write newline sends the cursor at
the first of the next line in screen.]

Psuedo Code -e
For i = 1 to 10
{
For j = 2 to 6
{
Write X
}
Write newline
}

[t Write X sk X ak a Write newline sk

20. What is the value of ctr when the following statement is complete?
for (ctr = 2; ctr < 10; ctr = ctr + 3) ;
[In C]
For ctr = 2 to 10 step 3
[In BASIC]

[2.5]

( mn ctr e ?
for (ctr = 2; ctr < 10; ctr = ctr + 3) ;

For ctr = 2 to 10 step 3

[C ]

[BASIC ] )

You might also like