ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
There is a 100-story building and you are given two eggs. 
The eggs (and the building) have an interesting property 
that if you throw the egg from a floor number less than X, 
it will not break. And it will always brake if the floor 
number is equal or greater than X. Assuming that you can 
reuse the eggs which didn't broke; you got to find X in a 
minimal number of throws. Give an algorithm to find X in 
minimal number of throws.
 Question Submitted By :: San
I also faced this Question!!     Rank Answer Posted By  
 
  Re: There is a 100-story building and you are given two eggs. The eggs (and the building) have an interesting property that if you throw the egg from a floor number less than X, it will not break. And it will always brake if the floor number is equal or greater than X. Assuming that you can reuse the eggs which didn't broke; you got to find X in a minimal number of throws. Give an algorithm to find X in minimal number of throws.
Answer
# 1
We should start from the second floor to identify the X 
floor. 

Step 1. Throw the one egg from second floor, 
if it breaks in second floor then go to first floor, 
through remaining one from the first floor
	if it breaks on the first floor then X=1
else 
	X=2

If does not break in second floor, goto fourth floor and 
throw the egg
if it breaks in fourth floor then go to third floor, 
through the remaining egg from the third floor
	if it breaks on the third floor then X=3
else
	X=4

Similarly we should run floor = floor + 2, till one egg 
breaks, 

floor = floor + 2
if one egg breaks at floor  then 
Set currentfloor = floor -1 and check for remaining egg 
throw from currentfloor, if egg breaks at currentfloor, 
then X= currentfloor else X=floor
Else
	floor = floor + 2

do until floor =100
 
Is This Answer Correct ?    4 Yes 22 No
Basvaraj S Pinna
 
  Re: There is a 100-story building and you are given two eggs. The eggs (and the building) have an interesting property that if you throw the egg from a floor number less than X, it will not break. And it will always brake if the floor number is equal or greater than X. Assuming that you can reuse the eggs which didn't broke; you got to find X in a minimal number of throws. Give an algorithm to find X in minimal number of throws.
Answer
# 2
Find a number n such that n(n+1)/2>=99. (You'll know why
later).  n=14 in this case.
Throw one egg from 14th floor. 
If it breaks, 
start throwing the other egg starting from the 1st floor,
bottom up till it breaks. Max no of throws(worst case)=1+13=14.
else Throw the egg from (14+13)= 27th floor. If it breaks
start throwing the other egg from 15th floor bottom up. Max
no of throws=2+12=14. 
Continue till you find the floor. 
In the worst case, you'll have to do 14trials compared to
the rather large figures provided by other solutions. 
Regards,
J1g54w H4ck3r
 
Is This Answer Correct ?    21 Yes 5 No
J1g54w H4ck3r
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
what is the return value (status code) of exit() function.... what the arguments(integer value) passed to it means.... TCS1
#define f(x) main() { printf("\n%d",f(2+2)); }  3
which one of follwoing will read a character from keyboard and store in c a)c=getc() b)c=getchar() c)c=getchar(stdin) d)getc(&c) e)none  5
how to make c program without a libary? e.g.#include<stdio.h> libary is not in c progaram.  1
define function Assurgent4
f(char *p) { p=(char *)malloc(sizeof(6)); strcpy(p,"HELLO"); } main() { char *p="BYE"; f(p) printf("%s",p); } what is the output? Hughes6
Look at the Code: #include<string.h> void main() { char s1[]="abcd"; char s2[10]; char s3[]="efgh"; int i; clrscr(); i=strcmp(strcat(s3,ctrcpy(s2,s1))strcat(s3,"abcd")); printf("%d",i); } What will be the output? A)No output B) A Non Integer C)0 D) Garbage Accenture5
what is use#in c  3
write an interactive program to generate the divisors of a given integer. TCS4
Difference between Class and Struct. Motorola6
main() { float a=3.2e40; printf("%d",a); } Satyam5
Total of how many functions are available in c?  2
Write a programme to find even numbers without using any conditional statement? Infosys3
how to find that no is int or float?  5
how to print value of e(exp1)up to required no of digits after decimal?  1
1. Write the function int countchtr(char string[ ], int ch); which returns the number of times the character ch appears in the string. Example, the call countchtr(“She lives in NEWYORK”, ‘e’) would return 3.  2
Who is invented by c? Infosys14
for(i=0;i=printf("Hello");i++); printf("Hello"); how many times how will be printed?????????  4
#define MAX(x,y) (x) > (y) ? (x) : (y) main() { int i = 10, j = 5, k = 0; k = MAX(i++, ++j); printf("%d %d %d", i,j,k); } what will the values of i , j and k? } NDS9
what is use of loop? Infosys6
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com