Other C++ Code Interview Questions 

Question 
Asked @ 
Answers 

program to find the magic square using array 

1 
Given 1 to n random number, find top 10 maximum numbers and
explain the time complexity of the algorithm. 
NetApp 
1 
Write a program using twodimensional arrays that determines
the highest and lowest of the 12 input values.
Example:
Enter 12 numbers:
13 15 20 13 35 40 16 18 20 18 20 14
highest: 40
lowest: 13


1 
A research student is given a singlylinked list. Each node
of the list has a color, which is either “Black”
or “White”. He must find if there are more black nodes than
white nodes, or vice versa. His advisor
gives him 5,000Rs to buy a computer to do the work. He goes
to the computer store and finds a
slightly defective computer which costs a mere 3,000Rs. This
computer has the small problem of not
being able to do arithmetic. This means that he cannot use a
counter to count the nodes in the list to
determine the majority color. The computer is otherwise
fully functional. He has the evil idea that he
could buy the defective computer and somehow use it to do
his work, so that he can use the rest of
the money on enjoyment. Show how he can accomplish this
amazing task. Write code for an algorithm
called ‘findMajorityColor’ which takes a singlylinked list,
L, with n nodes and returns the majority color
among nodes of L. This algorithm should have the same
asymptotic running time as counting the
nodes (O(n)). Note: No arithmetic is allowed. 

1 
Faster Computers
Suppose you have a computer that requires 1 minute to solve
problem instances of size 1000. What instance sizes can be
run in 1 minute if you buy a new computer that runs 1000
times faster than the old one, assuming the following time
complexities T(n) for our algorithm?
(a) T(n) = O(n).
(b) T(n) = O(n3).
(c) T(n) = O(10n). 
QatarUniversity 
1 
can we declare an object of a class in another class?(assume
both class as public classes) 
Microsoft 
1 
MinMax
Write an algorithm that finds both the smallest and largest
numbers in a list of n numbers and calculate its complexity
T(n).

QatarUniversity 
1 
1.program to add any two objects using operator overloading
2.program to add any two objects using constructors
3.program to add any two objects using binary operator
4.program to add any two objects using unary operator 
IBM 
2 
Here's the programm code:
int magic(int a, int b) {
return b == 0 ? a : magic(b, a % b);
}
int main() {
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", magic(a, b));
return 0;
}
on input stream we have integers 4, 45
What's the output integer?
How many times will be initiated "magic" function? 

1 
Write a program that takes a 3 digit number n and finds out
whether
the number 2^n + 1 is prime, or if it is not prime find out
its
factors.

Amazon 
4 
write a program in c++ to scramble a bmp image file using a
scramble key 0x7c and an XOR logic. print out the original
image, the scrambled image and the program.
Note: the first 24bytes of a bmp file contain the header
information of the file. 

1 
What will be the output
for(i=1;i<=3;i++)
{
printf("%d",i);
continue;
i++;
} 
Impetus 
5 

For more C++ Code Interview Questions Click Here 