Вы находитесь на странице: 1из 5

# Analytical Part 1.

You and your friend are playing a game with a fair coin (head and tail are equally likely). At first you will toss the coin. Then your friend (if the game is not over). Then you again and this continues until the game ends. The player who will get a head on the coin will win the game and the game ends. (3 !) i. "hat is the pro#a#ility that the game will finish in less than \$ move% ii. "hat is the pro#a#ility that you will win the game% Ans :

&. 'ere is a function that reverse a num#er . if the parameter n ( 1&3) * the function will return r where r ( )3&1. +ut one of the line of the function is missing. You have to write the missing line. (!) int reverse(int n) { int r = 0; while(n>0) { //Here is the missing line n=n/10; } return r; } Ans :

3. ,ittle - is writing a program to check whether two rectangles (say the are A and +) intersect each other. 'er algorithm is simple. .he takes rectangle A and checks whether each verte/ of it lies within rectangle +. 0s there any flaw in her algorithm% 1raw counter e/ample if there is any. (2) Ans :

). ,ook at the following pseudo code. ans := 0 for i := 1 to N do for j := i + 1 to N do for := j + 1 to N do !ns := !ns + 1 3ow find the formula for ans for a given N. Ans : (!)

!. 'ow many ways to arrange \$ cows and 4 donkeys in a line to take photo% 5uriously you can not distinguished a cow from other cows and you can not distinguished a donkey from other donkeys. (!) Ans :

\$. 6ind the sum. "=1 #=10000000000000 long long int sum=0; for(long long int i = "; i \$= #; i++) sum += (i % i) & '; Ans :

(!)

2. A num#er is written with &2 ones. 0s it a multiple of &2% 7rove your answer and find the remainder. (18) Ans :

4. 'ow many non9prime num#ers:()8 which are divisi#le #y the sum of their prime factors% (2) Ans :

;. The dou#le data9type in 5 has \$) #its of which are 1 #it for sign* 11 #it for e/ponent and !& #it for mantissa (fraction). "hat is the largest irrational num#er that is possi#le to fully store in dou#le data9type% </plain. (3) Ans :

18. You have a grid of squares* which must #e either filled in #lack or marked with =. +eside each row of the grid are listed the lengths of the runs of #lack squares on that row. A#ove each column are listed the lengths of the runs of #lack squares in that column. Your aim is to find all #lack squares. (&8) 3 3 11 21 15 17 16 6 4 2 1 1 2 4 4 3 2 2 3 6 8 5 7 3 1 3 1

11.,ook at the following code. unsigned int f(unsigned int n) { if (n == 1) return 1; else return f(n/() + f(n ) n/() + 1; } void m!in() { unsigned int sum = 0; for (unsigned int * = 1; i \$=1000000000; ++i) sum += f(i); +rintf(,&ud-n,. sum); } "hat is the output% Ans :

(1!)

1&. >ne of the questions in this paper (#oth analytical and programming) has it?s mark written in #inary. 5an you identify it% "rite the pro#lem num#er. (18) Ans :

13.,ook at the following code. void /un0tion(int ") { if("\$=0) { +rint(,1 ,); return; } else { /un0tion(")1); /un0tion(")(); } } 0f i call 6unction(!) * how many times = will #e printed% Ans :

(4)

Programming Problems 1. @aAohn has n indistinguisha#le caps. 'e put them on a desk in a particular order and went out. After returning* he came to know that someone changed the order of the caps so that only one cap is in its original position and each of the other caps are in a position originally occupied #y a different cap. 'e #egan to wonder how many order of caps can #e possi#le. (! 18) "hat is the answer when n ( ) and n ( &8% &. 'ow many times a#a su#sequence e/ist in the given string%
2!s# :) !!33!33!33!3! H!rd:) !!33!33!33!3!!3!3!3!3333!333!3!3!3!33!33!33!3!3!33!3!33!3!!33!33!3!!33!333!3! Note:- 0n mathematics* a subsequence is a sequence that can #e derived from another sequence #y deleting some elements without changing the order of the remaining elements. 6or e/ample* the sequence (A* +* 1) is a su#sequence of (A* +* 5* 1* <* 6).

3. You are given these points in &d plane. ()'4.)51) (67.)8') ()44.'') ()((.9) (99.)49) (7'.'0) ('7.)18) ()79.) 4() (100.)5() ()(.(') ()(8.)'1) ()(7.)69) ()(4.)4() ('1.)'5) (77.6() ((0.)9') (9'.)9) ()45.56) ()40.(8) ()91.57) ,ine B, C passes through the ma/imum num#er of points. "hat are those points% 6or multiple answers* any of them will do* #ut points are to #e listed in order of their appearance in the original list. (1!) ). 'ow many continuous su#9sequence of the following sequence has a sum divisi#le #y 13% (1. 1. 5. 6. 1(. '. 1(. 8. 7. (. 6. (. 10. (. 9) (18)