Wednesday, September 5, 2007

Programming puzzles ... dare to solve

Programming puzzles ..... these are quite boring for the masters and experts , neways have a look at it ... i guess it will be fun for new experts .... and posts the answers as comments without checking out provided forum post.

Q1 Write a "Hello World" program in 'C' without using a semicolon.
Q2 Write a C++ program without using any loop (if, for, while etc) to
print numbers from 1 to 100 and 100 to 1;
Q3 C/C++ : Exchange two numbers without using a temporary variable.
Q4 C/C++ : Find if the given number is a power of 2.
Q5 C/C++ : Multiply x by 7 without using multiplication (*) operator.
Q6 C/C++ : Write a function in different ways that will return f(7) =
4 and f(4) = 7
Q7 Remove duplicates in array
Q8 Finding if there is any loop inside linked list.
Q9 Remove duplicates in an no key access database without using an
array
Q10 Write a program whose printed output is an exact copy of the
source. Needless to say, merely echoing the actual source file is not
allowed.
Q11 From a 'pool' of numbers (four '1's, four '2's .... four '6's),
each player selects a number and adds it to the total. Once a number
is used, it must be removed from the pool. The winner is the person
whose number makes the total equal 31 exactly.
Q12 Swap two numbers without using a third variable.
Given an array (group) of numbers write all the possible sub groups of
this group.
Q14 Convert (integer) number in binary without loops.

Al

http://www.praveen.ws/journal/2006/09/04/c-and-c-puzzles/
http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2004-06/2652.html
http://www.velocityreviews.com/forums/t284024-programming-puzzle.html

1 comment:

alokadvin said...

Q4 C/C++ : Find if the given number is a power of 2.

#include < stdio.h >

int
main()
{
int a;
printf( "Enter the number to be tested: " );
scanf( "%d", &a );
if( a && ( a & ( a - 1 ) ) == 0 ) {
printf( "The number %d is a power of 2\n", a );
}
else {
printf( "The number %d is not a power of 2\n", a );
}
return 0;
}