Monday, July 27, 2009

some of Subex c questions

1. #include
void main()
{
int arr[]={0,1,2,3,4,5};
int i;
int *p=arr;
*p+2=10;
for(i=0;i<6;i++)
printf(“%d\n”,arr[i]);
}



2. enum marks
{
che, phy=53, math;
};
struct s
{
char name[15];
enum marks m;
}k;
void main()
{
strcpy(k.name,”Tom”);
k.m=phy;
printf(“name:%s\n”,k.name);
printf(“Physics marks:%d\n”,k.m);
k.m=che;
printf(“chemistry marks:%d\n”,k.m);
}


3. What is the o/p of the following statement?
cout<<(100==100);


4. void main()
{
extern int i;
i=20;
printf(“%d”,i);
}


5. void main()
{
int i=5;
int arr[]={-1,2,3,4,5};
for(;i==0;i++)
printf(“%d\n”,arr[i]);
}


6. void main()
{
int i=5,k;
k=++i==6;
printf(“%d\n”,k);
}

7. void main()
{
int size=10;
int arr[size];
printf(“%d”,sizeof(arr));
}



8. #include
#define first 5
#define second 7
#define last first+second
void main()
{
int i;
i=last*last;
printf("%d",i);
}

9. #include
struct s
{
int i;
struct s p;
}k;
void main()
{
k.i=10;
printf("%d",k.i);
}


10. void main()
{
char ch;
scanf(“%c”,&ch);
printf(“%c\n”,ch);
scanf(“%c”,&ch);
printf(“%c\n”,ch);
}

If ‘a’ is given as i/p o/p will be
a
a

If 4 ‘a’s are to be printed,(i/p,o/p,i/p,o/p) the fflush() function should be used.

11. void main()
{
char s1[]=”hi”;
char s2[]=”hi”;
if(s1==s2)
printf(“same”);
else
printf(“Different”);
}

Saturday, July 25, 2009

Logic! Logic!! Logic!!!

This problem proves that you are gullible.

A puzzle to ponder

You have to make 125 packets of sugar with first one weighing 1 kg, second 2 kg, third 3 kg etc ...and 125th one weighing 125kg.You can only use one pan of the common balance for measurement for weighing sugar, the other pan had to be used for weights i.e. weights should be used for each weighing.
It has come into notice that moving weights into and out of the pan of the balance takes time and this time depends on the number on the number of weights that are moved. For example - If we need to measure 4 kg using weights 1 and 3 only, it will take twice as much time needed to measure 1 kg. Lets say we want to make sugar packets of weights 1,3,4 using weights 1 and 3 only. For this first we measure 1 kg, with 1 unit of time, we place 3 kg along with 1 kg and measure 4kg with again 1 unit of time, and finally we move 1kg out of pan to measure 3kg in 1 unit of time. So in 3 units of time we could measure 1,3 and 4kg using weights 1 and 3 only.

Now you have to make sugar packets of all weights from 1 to 125 in minimum time, in other words in minimum movement of weights. The question here is to find out the minimum number of weighs needed and the weight of each the weights used and the strategy to be followed for the creation of 125 packets of sugar.

Classic MS problem

* You are given 2 eggs.
* You have access to a 100-storey building.
* Eggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100 th floor.Both eggs are identical.
* You need to figure out the highest floor of a 100-storey building an egg can be dropped without breaking.
* Now the question is how many drops you need to make. You are allowed to break 2 eggs in the process

Wise King


Party confusion

A and B go to a dinner with four other couples, each person shakes hands with every other person he or she doesn't know. Later A does a survey and discovers that everyone of the nine other attendees shook hands with a different number of people. How many people did B shake hands with?

If you are a genius answer it in 10 seconds


The chessboard has been the source of all kinds of puzzles that
explored mathematical ideas, ever since it came into use centuries ago. One
that finds its way into virtually every puzzle anthology because of its
apparent difficulty, yet deceptively simple solution, is the following:
If two opposite corners of a checkerboard are removed, can the
checkerboard be covered by dominoes? Assume that the size of each
domino is the size of two adjacent squares of the checkerboard. The
dominoes cannot be placed on top of each other and must lie flat.
A gold coin is in one of the following three boxes, each of which has
an inscription written on it as follows:

A:Coin is in here
B:Coin is not in here
C:Coin is not in A

Can you tell where the coin is if, at most, only one of the inscriptions is true?

Rip the blindfold

Before they are blindfolded, three women are told that each one will
have either a red or a blue cross painted on her forehead. When the blindfolds
are removed, each woman is then supposed to raise her hand only if
she sees a red cross and to drop her hand when she figures out the color of
her own cross. Now, here’s what actually happens. The three women are
blindfolded and a red cross is drawn on each of their foreheads. The blindfolds
are removed. After looking at each other, the three women raise their
hands simultaneously. After a short time, one woman lowers her hand and
says, “My cross is red.” How did she figure it out?

This question gave us a new idea

A certain man put a pair of rabbits, male and female, in a very large
cage. How many pairs of rabbits will be produced in that cage in a
year if every month each pair produces one and only one new pair,
consisting again of a male and a female, which, from the second
month of its existence on, also is productive? It is assumed that none
of the rabbits die in that year.

UNLUCKY BREAKDOWNS

On an occasion of great festivities a considerable number of townspeople
banded together for a day's outing and pleasure. They pressed into service
nearly every wagon in the place, and each wagon was to carry the same num-
ber of persons. Half-way ten of these wagons broke down, so it was necessary
for every remaining wagon to carry one more person. Unfortunately, when
they started for home, it was found that fifteen more wagons were in such bad
condition that they could not be used; so there were three more persons in
every wagon than when they started out in the morning.
How many persons were there in the party?

WHEN DID THE DANCING BEGIN?

"The guests at that ball the other night," said Dora at the breakfast table,
"thought that the clock had stopped, because the hands appeared in exactly
the same position as when the dancing began. But it was found that they had
really only changed places. As you know, the dancing commenced between
ten and eleven oclock. What was the exact time of the start?"