0 évaluation0% ont trouvé ce document utile (0 vote)
105 vues12 pages
If you've got someone working for you for seven days and a gold bar to pay them, how do you pay them? Divide gold bar into 3 parts 1 bar,2 bar and 4 bar by making 2 cuts day 1Give away 1 bar day 2Take away 1 bar and give 2 bar day 3Give again 1 bar day 4Take away 1 and 2 bar and give 4 bar day 5Give 1 bar (4+1=5) day 6Give a cake, a corner has been broken. If gives a cake to a
If you've got someone working for you for seven days and a gold bar to pay them, how do you pay them? Divide gold bar into 3 parts 1 bar,2 bar and 4 bar by making 2 cuts day 1Give away 1 bar day 2Take away 1 bar and give 2 bar day 3Give again 1 bar day 4Take away 1 and 2 bar and give 4 bar day 5Give 1 bar (4+1=5) day 6Give a cake, a corner has been broken. If gives a cake to a
If you've got someone working for you for seven days and a gold bar to pay them, how do you pay them? Divide gold bar into 3 parts 1 bar,2 bar and 4 bar by making 2 cuts day 1Give away 1 bar day 2Take away 1 bar and give 2 bar day 3Give again 1 bar day 4Take away 1 and 2 bar and give 4 bar day 5Give 1 bar (4+1=5) day 6Give a cake, a corner has been broken. If gives a cake to a
1)There is a room with a door (closed) and three light bulbs.
Outside the room there are three
switches, connected to the bulbs. You may manipulate the switches as you wish, but once you open the door you can't change them. Identify each switch with its bulb. Ans 1) As you can only open door once.So lets take 3 switches as A,B,C and lets take bulb as X,Y,Z.So first turn on the switch A for some time lets say 4-5 minutes then switch it off.Now turn on any other switch from B or C.Now enter the door and see the bulbs.The one which is on corresponds to the switch you just turn on,Now touch the bulbs,the bulb which is hot corresponds to the switch you turn on first that is A and the bulb which is cold corresponds to the switch you didn't turn on. 2)You've got someone working for you for seven days and a gold bar to pay them. The gold bar is segmented into seven connected pieces. You must give them a piece of gold at the end of every day. If you are only allowed to make two breaks in the gold bar, how do you pay your worker? Here you put one condition in front of worker that he cannot spent any of the gold bar until he is fully paid. Ans 2) Divide gold bar in 3 parts 1 bar,2 bar and 4 bar by making 2 cuts
day 1- Give away 1 bar day2- Take away 1 bar and give 2 bar day 3- Give again 1 bar (2+1=3) day 4- Take away 1 and 2 bar and give 4 bar day 5- Give 1 bar (4+1=5) day 6- Take away 1 bar and give 2 bar (4+2=6) day 7 -Give 1 bar (4+2+1=7) 3)Why is a manhole cover round? Ans 3) This question is asked in interview to check whether you can give more then one answer for on question (basically they wanted to check that whether you have more then one approach for one problem i guess).So you can give different answers like pipes and tubes are round so the manhole or round manhole can be easily rotated or rolled or something like that.Remember tell atleast something instead of telling i don't know.They will appreciate that. 4)If gives a cake, a corner has been broken. How do u cut the rest in two equal parts? Ans 4) Cut along Z-axis 5)What is the color of the bear when dropped from a height of 20 m and take 2 second? Ans 5) As the bear is dropped its initial velocity will be 0 that is u=0.Now consider the equation S=ut+at^2*0.5 a=2S/t^2 a=10m/secsq Thus acceleration is g=10 which is only in the poles.South pole don't have bear so it should be North pole and polar bear are there which are of white color. 6)Can you make 120 with 5 Zeroes? Ans6) (0!+0!+0!+0!+0!)!=120 7)Numbers of Zero at the end of 100 !? Ans 7) 24 8)You have 4 jars of pills. Each pill is a certain weight ie 10 gram, except for contaminated pills contained in one jar, where each pill is weight 1 less then original. How could you tell which jar had the contaminated pills in just one measurement? Ans 8) Take 1 pill from first 2 pills from second and so on.Now put all the pills on scale and weight.If it is one less then expected weight then the contaminated pill is in first,if it is two less then expected weight then contaminated pill is in second and so on. 9)How will you measure height of building when you are at the top of the building?And if you have stone with you. Ans: Drop the stone and find the time taken for the stone to reach the ground. find height using the formula s = u+ at ( s = height, u= initial velocity=0, a= g=9.8m/s, t = time taken)
10)One train leaves A at 15mph heading for B. Another train leaves from B at 20mph heading for A on the same track. If a bee, flying at 25mph, leaves from A at the same time as the train and flies back and forth between the two trains until they collide, how far will the bee have traveled?
---------------------------------------------------------------------------------------------------------------------------------- 1) If you are entering a room and your head strikes with the bulb which is hanging from the ceiling of the room. What will be the height of the room? 1) Its Simple. You first need to think how you will calculate the height of the room. You know your height can help you in calculating the room of height so whats left to add in your height to calculate the height of the room? Its the length of bulb wire hanging from the ceiling of the room. Now how to calculate the height of the bulb wire? You must have studied Simple harmonic motion in your +2. So calculate the approx time period a bulb is taking manually and then just apply the formula of Time period of SHM to calcualte the length of bulb wire T = 2*Pi*(L/G)^(1/2) So now height of the room is your height+Length of bulb wire
2) There is a vending machine which have 3 buttons for Milk , Coffee and Tea but the each of them is labelled differently and you dont know which button gives what and you need to put 5 Rupees if you want to drink anything. So how much minimum money you will have to spend to determine which button gives what ? There will be 2 possiblities of finding out the correct button for the drinks a) You inserted 5 rupees in vending machine and then pressed button of Milk.As the button is labelled incorrectly it will give you either Tea or coffee. Suppose its a Tea so now you know that Milk labelled button is actually Tea button. The remaining button is of Tea and Coffee. coffee cannot be coffee so it is milk and the button Tea is coffee b) Suppose the milk button is Coffee. Now the remaining button is tea and coffee. Tea button cannot be tea so it will be a milk and coffee button will be Tea. Thus in any of the case you just have to spend minimum 5 rupees only 3) You are riding a horse and to the right of you is a bear running at your same speed, to your front one elephant is running with the speed more then you and you cannot overtake it , and to your left one hippo is running at the same speed. A lion is chasing you very fast. How will you save yourself? 3) Tell the person to stop merry-go-round and get off
4) How many Bricks you need to complete 100 Buildings made up of Bricks? 4) One. The last brick in 100th building.
5) Jamie lives in a house which has 4 windows on each wall and each window has southern View. One day he saw a bear coming towards his home. What is the color of Bear? 5) White. As all the windows have southern view that is possible only in North Pole so the Bear is Polar Bear
6) Once lived a king who made a bridge from his kingdom to neighbouring Kingdom only for his travel to meet other kings. He ordered one guard that if he see anyone from his kingdom escaping through bridge then Shoot him/her and if somebody coming from other other kingdom then sent him/her back. The guard was staying inside his small hut near bridge.He watch out the bridge in night for 20 minutes and go back to his hut for 5 minutes to take rest. The total time takes to cross the bridge is 8 minutes. Despite of this one man manage to cross the bridge without getting killed and harming the guard. How is this possible? 6) When guard went inside his hut for 5 minutes. The man started crossing the bridge. After reaching more then half way in 5 minutes, when it was time for Guard to come out he changed his direction towards the kimgdom. So guard thought he is coming from other kingdom and sent him back.
7) You Stay in DELHI. PUNJAB is 400 KM far away from DELHI. INDORE is 900 KM away from DELHI. How Far is JAMMU from DELHI? 7) It will be 500 KM. As PUNJAB is 400 KM and INDORE is 900 KM. We can observe from both words PUNJAB and INDORE that the value of Vowels is 400 and value of consonants is -100. So JAMMU will be (A+U)=800 and (J+M+M)= -300.
1. You are given two candles of equal size, which can burn 1 hour each. You have to measure 90 minutes with these candles. (There is no scale or clock). Also u r given a lighter.
Ans: 1. First light up the two ends of the 1st candle. When it will burn out light up one end of the second candle. (30+60=90)
2. Try the similar problem to measure 45 minutes.
Ans: First light-up the two ends of the 1st candle and one end of the 2nd candle.
When the 1st candle will burn out ,then light up the both ends of the 2nd candle (15+30=45) 3. You r given a thermometer. What can u do by this without measuring the temperature?
Ans: if u put thermometer into a tree it wont grow anymore, will just die off
4. How it is possible to place four points that are equidistance from each other?
OR U r a landscape designer and your boss asked u to design a landscape such that you should place 4 trees equidistance from each other. (Distance from each tree to the other must be same) Ans: Only 3 points can be equidistant from each other. But if u place points in the shape of a pyramid then its possible 5. You are given a cake; one of its corner is broken. How will u cut the rest into Two equal parts?
Ans: Slice the cake
6. How will you recognize the magnet & magnetic material & non-magnetic material?
Ans: Drag one piece of material over another. There is no attractive force in the middle portion of the magnet.
OR Get a piece of thread and tie up with the one bar and check for poles. If it iron bar then it moves freely and if it is magnetic bar then it fix in one direction according to poles.
7. If one tyre of a car suddenly gets stolen.... and after sometime u find the tyre without the screws how will u make ur journey complete?
Ans: Open 3 screws, 1 from each tyre and fix the tyre.
8. How can u measure a room height using a thermometer?
Ans: temp varies with height. but its dependent on various other factors like humidity, wind etc.
9. What is the height of room if after entering the room with a watch ur head strikes a hanging bulb?
Ans: Oscillate the hanging bulb. Calculate the time period for one complete oscillation by Simple Harmonic Motion (SHM) of the handing bulb. Put it in the formula T=2 * 3.14 * (L/G)^1/2 L will be the length of the hanging thread. Add the L with ur height to get the height of the room.
OR Ans: Drop it from the room and find the time at which it strikes the floor. Using physics formula s = (at^2)/2 (IM NOT SURE ABOUT THIS ONE)
10. Color of bear.... if it falls from 1m height in 1s.
Ans: We get 'g' perfect 10 which is only in poles...hence polar bear...color White
11. How will you measure height of building when you are at the top of the building? And if you have stone with you.
Ans: Drop the stone and find the time taken for the stone to reach the ground. find height using the formula s = a + gt ( s = height, a= initial velocity=0, g=9.8m/s, t = time taken)
12. How wud u catch and receive a ball in same direction? (Dropping is from north And receiving from bottom not accepted, as it is 2 directions)
Ans: ?
13. 25 statements given. Some tell truth, some false and some alternators. Find out the true statements.
15.There are three people A, B, C. Liars are of same type and Truth speaking people are of same type. Find out who is speaking truth and who is speaking false from the following statements:
a) A says: B is a liar. b) B says: A and C are of same type.
Ans: lets assume A is speaking truth. It means B is a liar then it means A and C are not of same type.
16.5 swimmers A, B, C, E, F and many conditions of their positions like there are Two b/w A & F, B doesn't win etc the question was to find who was b/w like E & D?
Ans: ?
17. in a race u drove 1st lap with 40kmph and in the second lap at what speed u must drive so that ur average speed must be 80kmph.
Ans: its impossible! if u drove the first lap in 40 kmph, its impossible that the average speed of both the laps is 80kmph.
for eg. consider one lap distance = 80km. time req. to cover 1 lap = 80km/40kmph = 2 hrs.
if the avg. speed is 80kmph, then the total time would have taken =
160kms/80kmph = 2 hrs.
same is the case with any other distance u consider. so the avg to be 80kmph is impossible
18. You have to draw 3 concentric circles with a line passing thru their center without lifting hand.
Ans: Start the line complete one circle move inside circles along the line and then draw second circle. Like wise rest.
19. A rectangular paper is there. At a corner a rectangular size paper is taken from it. Now you have to cut the remaining paper into two equal halves.
Ans: try it on the paper. You must fold the part that has complete paper and select Half of it and then fold the part that cut and selects half of it and then cut along the folding. (I DONT UNDERSTAND THIS ONE!!)
20. Value of (x-a)(x-b)..(x-z)
Ans: 0 as theres X-X term
21. There are 9 coins. 8 are of 1 gm and 1 is of 2 grams. How will you find out the heavier coin in minimum number of weighing and how many weighing it will need?
Ans: 2 weighing ( Divide the number of coins into 3 parts at each weighing)
The above printf line gives output like this because printf returns the number of character successfully written in the output.So the inner printf("%s","ILOVECPROGRAM") writes 13 characters to the output so the outer printf function will print 13 and as 13 is of 2 characters so the next outer printf function will print 2 and then next outer printf will print 1 as 2 is one character.So is the output 1321.
2) What will be the output of the following conditional operator.
The above code snippet is very simple actually but it is made to look like that it is very tough and most of us start solving the nested part without thinking a bit although we know the concept.So first think for five minutes.The concept behind this is when we use conditional operator then if the condition is true then we select the value before the colon and if it is false then the value after the column. For example a>b?a:b.If a is greater then b then a otherwise b.So we have 0 before ? operator that means false so no need to see the nested thing.The answer will be 1.
What should be the condition inside if statement such that it will print "I Love C Language" ?
Ans- if(!printf("I Love"))
As the printf returns the number of characters successfully written on output it will return 6.And making it not will invert and make it 0 so else statement will print out.
4) Program to identify even or odd number without using any arithmetic operator,conditional statement,logical operators,Relational operator.This program was asked in Microsoft written test.
Ans- int main() { int no; scanf("%d",&no); (no&1)?printf("odd"):printf("even"); }
The above question can be solved using bitwise AND operator as it is not mentioned in question not to use.And also you can use conditional operator as conditional statement cannot be used.Taking bitwise AND of any number with 1 will give value y where y=0 if number is Even and y=1 if number is Odd because even number always ends with 0 so 0001 & ---0 will always give 0.On the other hand odd number always have 1 in last position so 0001 & ---1 will always give
5) Program to find the sum of the digits of a number in single statement.
Ans- int sum(int x) { int s; for(s=0;x>0;s+=x%10,x/=10); return s; } 6) Print number from 1-100 without using loop,Recursion and Goto.
Ans- void *realloc(void *ptr,size_t size); if size=0 then call to realloc is equivalent to free(ptr)
As realloc is used to deallocate previously allocated memory and if the size=0 then it will acts as free().
1) Function pointers : Function pointers is the topic which looks easy to understood but its not, that's why it is the common topic to be asked in interviews by companies. So what is the tricky part here? Well we will see with examples Lets look at some different types of function pointers examples :
a) int (*func)( ) : This is the normal function pointer example in which func is pointer to a function which returns int
b) int **func( ) : This is normal function whose return type is pointer to pointer to int (Please keep in mind this is not function pointer but it is just a normal function)
c) int *(*func)( ) : Now this is different from b as there are parantheses now and it make a difference.So Please dont be confused. Here func is pointer to a function whose return type is pointer to int
d) int (*func[])( ) : Here func is array of pointers to function which returns int
e) int *(*func())[] : People often get confused here in interviews. Here func is pointer to a function whose return type is pointer to an int array.
2) Macros : Macros are simple yet tricky unit of programming. Although it is not advisable to use macro in programming but it is one of the favourite topic in interviews to confuse people. So better be clear in it before going to interview. Now how is it tricky? Lets see some of the examples of Macros
a) #define Mul (X,Y) X*Y z= Mul (3+5,8+2); printf("%d",z);
Now what will be the answer?. I assume most of you must be knowing the trick here but for those who dont let me tell you that answer will not be 80 as most of you might be thinking. Answer is 45. How? when you call Mul (3+5,8+2) it substituted the value as it is in X*Y that is 3+5*8+2. So now 5*8 will be evaluated first followed by adding 3 and 2.
b) #define Mul (X,Y) X*Y z= Mul (3+5,8+2)%2; printf("%d",z);
What will be the answer now? does it will be like z=45%2 ? Actually No..I myself made mistake in one of the interviews in this question. Again macros will substitute first and then evaluate. So z=3+5*8+2%2. Here % will evaluate first due to associativity and the answer will be 43.
Similarly interviewers can change small things in this type of problems and can play with you in interview. So try to modify the above problems in your compiler and check the output. The only thing you have to remember in macro is substitute and then evaluate.
Program to add two numbers without using + or any other arithmetic operator
where width is substituted in place of * in %*d and char is printed the number of times the width.
Explanation:-
In the above program " " is first printed m times followed by n times.So printf will return total number of " " which is nothing but m+n.
Output:-
8
Interviews Questions asked by accenture, TCS, wipro Its a very good achievement to get selected in these IT Giants. These companies normally focus on checking concept and base of students rather then checking exceptional coding skills. So it is quite easy to crack their interview if you have strong base in computer science. Normally this companies ask simple C Puzzles or conceptual questions in C or C++.They can also ask from JAVA if you have mentioned it on your Resume. Some time they also ask about simple Logical puzzles involving out of box thinking.They just see your approach to solve problems. I will discuss some of the common questions they ask in interviews.
1) Function and operator Overloading
This is by far the most common Interview question asked by these companies.You will definitely encounter with this question in atleast one of your interview with above IT companies. So you need to be crystal clear in this concepts They generally ask the below questions :
a) What is Function Overloading/Operator overloading? b) What is the need of function overloading? c) Give some examples of function overloading d) What are the functions declaration that cannot be overloaded? See Function declarations which cannot be overloaded e) Give some examples of Operator Overloading
They normally dont ask big programs in function and operator overloading but make sure that you atleast know simple program of both. More focus should be on Basic questions
2) Pointers
Next is pointers which are the favourite topics among interviewers generally because students get confused in this part mostly. So you should be very good in pointers concept. Some common questions they will ask you will be :
a) What are Pointers with example? b) What is Dangling pointer? c) What is Null pointer? d) What are array pointers? e) What is function pointer? See Function Pointers f) Write simple program involving pointers
3) Class and Structures
These companies often ask about Class and Structures. So you need to be clear in this concepts as well. They ask both the concepts classes and structures to make sure that the student knows both C and C++ language and concepts in it well. They will ask you questions like
a) What is Structure/Class? b) Why we need Class in C++ c) Difference between Class and Structures d) How to find the size of Class and structures? See How to calculate size of Class e) What is Inheritance? f) What is Virtual class? g) What is Abstract class? h) What are Constructors and destructors?
The Best place to learn this Basic questions is from book by Balaguruswamy. It has detailed and easy explanation with examples.
Program to implement other arithmetic operators using + operator only
This is the program of implementing *,-,/ using + arithmetic operator.
#include<stdio.h> #include<conio.h> int multiply(int i,int j) { int s=0; for(int k=0;k<j;k++) { s=s+i; } return s; } int substract(int i,int j) { int d=j<0?1:-1; return i+multiply(d,j); }
int divide(int i,int j) { int count=0; if(i>j) { int d=i;