Find output of the following code......
Software QA/Tests Interview Questions from Microsoft
(Continued from previous question...)
Find output of the following code......
Question:
Find output of the following code
int
mingle(int a, int b)
{
int c = b/2;
if (b<=1) { return a;}
cout<<c <<endl;
return a*(b-2*c) + mingle(a,c);
}
int
main()
{
int i;
for (i = 1; i<=5 ; i++) {
cout<<mingle(i+1,i-1)<<endl;
}
return 0;
}
maybe an answer:
2
3
1
4
1
10
2
1
6
maybe an answer2:
2
3
1
4
1
10
2
1
30
(Continued on next question...)
Other Interview Questions
- Whats a Linked List ? Given Two linked list forming a Y shaped linked list ......
- Given two strings, find the number of occurrences of one within the other ....
- Given two arrays, 1,2,3,4,5 .....
- Given an array of size n wherein elements keep on increasing monotically .......
- How do you implement a linked list without using dynamic memory .....
- Given two arrays like {1,2,3,4,5}......
- There are 10 Apple trees. A Farmer has placed these trees in 5 rows of 4 each... Can you tell me how to do it?
- Write a code to find if two linked list intersect
- Print a matrix spirally
- Given 2 sorted linked lists - merge them. Make sure you don't have duplicates in the merged list. .......
- More...
|