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?