ExploreNeedy
                       @ Your Choice
Share with -
  Feeds
  Technical
  Logical
  Puzzles
  Lectures
  Guestbook
HITS FlyArkaden.dk Free Web Counter

C/C++ Interview Algorithms


  1. Counting set bits in an unsigned number.
  2. Given two sets, Write a function to provide the union of them.
  3. Given four points in two dimentional pane, find is these points form a rectangle or not.
  4. Write a C function that will print 1 to N one per each line on the stdout where N is a int parameter to the function. The function should not use while, for, do-while loops, goto statement, recursion, and switch statement.
  5. Write program to implement the atoi() function?
Counting set bits in an unsigned number.

First solution:

int NoOfSetBits(int num) {
int count = 0;
while (num != 0) {
if (num & 1)
count++;
n = n>>1;
}
return count;
}


Second Solution (Optimized version):

short int CountSetBits(unsigned int num) {
short int count = 0;
while(num != 0) {
num = num & (num -1);
count++;
}
return count;
}
How would you detect a repeated element in an integer array.
Given two sets, Write a function to provide the union of them.
Given four points in two dimentional pane, find is these points form a rectangle or not.
Write an algorithm and write code to find two numbers in an array whose sum equals a given value
Question - 6

If you think that an important C/C++ interview questions or some answers are wrong in the site please contribute it to SiteAdmin@ExploreNeedy.com