Home »» Placement Papers »» All Papers »» Microsoft »» Placement Paper

whole-testpaper


1) Find output of following code?

void main()

 {

void *ptr;
char *a='A';
char *b="TAN";
int i=50;
ptr=a;
ptr=(*char)malloc(sizeof(a));
printf("%c",*ptr);
ptr=i;
ptr=(*int)malloc(sizeof(i));
printf("%d",++(*ptr));
ptr=b;
ptr=(*char)malloc(sizeof(b));
printf("%c",++(*ptr));

}

Ans: A51AN
 
2) Write a program that takes a no. from user and prints the no. subtracting 5 each time from the no. till the no. doesn’t crosses/reaches 0.And again prints the nos. Now increasing 5 each time till the no. doesn’t reaches/crosses original no. Don't use any loops or goto stmnt. And don't declare any local variables.

Ans: use recursion.

 
3) Convert a no. from string to integer.
 
Eg: str:"1234"
convert to int a=1234;
 
Ans: while(*ptr!=NULL)
{
a=(a*10)+(*ptr-48);

}

4) Find the subarray of an array that has the greatest sum? Array contains both +ve as well as -ve nos.

Ans: I did it using 3 loops but when I went for the 2nd technical round the interviewer told me a very simple and optimal program for the same.

sumtillnow=0;
sum=0;
for(i=0;i
{
sumtillnow+=a[i];
if(sumtillnow>sum)
sum=sumtillnow;
if(sumtillnow<=0)
sumtillnow=0;
}
 
5) Write test cases for a student regestration  form.
6) Write test cases for a web search engine.
Comment

0 Answers