473,839 Members | 1,514 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programming Puzzle

I found these questions on a web site and wish to share with all of u
out there,Can SomeOne Solve these Porgramming puzzles.
Programming Puzzles

Some companies certainly ask for these things. Specially Microsoft.
Here are my favorite puzzles. Don't send me emails asking for the
solutions.

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.

Q3,12 are similar , Q7 is simple & I know there answer For the Rest
please Help
Wiating for reply.
Nov 14 '05
271 20382
In <vf************ *************** *****@4ax.com> Mark McIntyre <ma**********@s pamcop.net> writes:
On Mon, 12 Jul 2004 18:33:25 +0200, in comp.lang.c , Irrwahn Grausewitz
<ir*******@fre enet.de> wrote:
Da*****@cern. ch (Dan Pop) wrote:
Whenever I make an accusation, I'm ready to support it rather than

Yeah? Like when Dan accused just about everyone else of being an idiot,


Accusing you of being an idiot is not exactly the same as accusing
"just about everyone else" of being an idiot.
yet refused to produce medical evidence to that effect? :-)


You produced yourself more than enough factual evidence. Thanks to
Google, it's here to stay ;-)

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #241
Da*****@cern.ch (Dan Pop) wrote:
In <i4************ *************** *****@4ax.com> Irrwahn Grausewitz <ir*******@free net.de> writes:
Da*****@cern. ch (Dan Pop) wrote:
In <5b************ *************** *****@4ax.com> Irrwahn Grausewitz <ir*******@free net.de> writes: <much snippage>Take your own advice and learn to read for comprehension, Dan!

I do.


Obviously not.
Do you?


I do my very best.


Which is no guarantee of success.


Deliberately acting like the idiot you consider others to be won't
help you here. There is not much of a guarantee for anything in the
real world.
No place for cowardice, since it wasn't an accusation, despite your
obvious lack of ability to differentiate in nuances, rather than
coercing each and every thing in some kind of crude binary system.


On the contrary, I'm quite good at differentiating nuances, therefore
I didn't miss the pejorative one behind your "neutral" question.


Thanks, Dan, you presented just another evidence supporting my theory.
And BTW, mimicking paranoid behaviour doesn't help much, too.
If you want to continue this discussion, feel free to send me a
private email.


Why should I bother? I have nothing to hide from anyone...


C'mon Dan, pretending you're an idiot two times in a single message is
far too much. Get real! My suggestion had nothing to do with hiding
something from someone, but everything with trying to move this OT
private discussion off the group, for the benefit of other readers.
You chose to ignore, so I choose to drop out.

Bye.
--
Irrwahn Grausewitz (ir*******@free net.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #242
In <gh************ *************** *****@4ax.com> Irrwahn Grausewitz <ir*******@free net.de> writes:
Da*****@cern.c h (Dan Pop) wrote:

Why should I bother? I have nothing to hide from anyone...


C'mon Dan, pretending you're an idiot two times in a single message is
far too much. Get real! My suggestion had nothing to do with hiding
something from someone, but everything with trying to move this OT
private discussion off the group, for the benefit of other readers.


Bogus argument. Those not interested have killfiled the thread long ago.
Neither you nor I have the slightest clue about who might be still
following this discussion and with what degree of interest.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #243
> Please describe (in code) a situation where two variables share the same memory
location.

Dan you need to try stuff for yourself

#include <stdio.h>

int main(void){
int x=10, *p;
p=&x;
printf("%p, %p\n",(void *)p,(void *)&x);
return 0;
}
Nov 14 '05 #244
"Michael" <mi************ @excite.com> wrote in message
news:20******** *************** ***@posting.goo gle.com...
Please describe (in code) a situation where two variables share the same memory location.

Dan you need to try stuff for yourself


Oohhhh.. you're arguing with Dan....

Duck everybody!
Nov 14 '05 #245
Mabden wrote:
"Michael" <mi************ @excite.com> wrote in message
news:20******** *************** ***@posting.goo gle.com...
Please describe (in code) a situation where two variables share the same
memory
location.


Dan you need to try stuff for yourself

Oohhhh.. you're arguing with Dan....

Duck everybody!


Eheheh (laughing behind a wall).
Nov 14 '05 #246
Michael wrote:
Please describe (in code) a situation where two variables share the same memory
location.

Dan you need to try stuff for yourself

#include <stdio.h>

int main(void){
int x=10, *p;
p=&x;
printf("%p, %p\n",(void *)p,(void *)&x);
return 0;
}


You need to think a little harder:

You have two variables: x and p. Are you saying that &x == &p? I sure hope
not.

Try again.
Nov 14 '05 #247
Julie <ju***@nospam.c om> writes:
Michael wrote:
Please describe (in code) a situation where two variables share
the same memory location.

Dan you need to try stuff for yourself

#include <stdio.h>

int main(void){
int x=10, *p;
p=&x;
printf("%p, %p\n",(void *)p,(void *)&x);
return 0;
}


You need to think a little harder:

You have two variables: x and p. Are you saying that &x == &p? I sure hope
not.

Try again.


No, of course nobody is saying htat &x == &p.

x and p are undeniably variables. The question is whether *p is also
a variable. If it is, the above program demonstrates a situation
where two variables share the same memory location; if it isn't, it
doesn't.

*p is certainly an object. The question of whether it's also a
"variable" is, in my opinion, a profoundly uninteresting one. The C
standard doesn't define "variable" as a technical term. It uses it
(informally) in a few places. It happens that it uses it only to refer
to declared objects, but we can't really infer anything from that.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #248
Keith Thompson wrote:

Julie <ju***@nospam.c om> writes:
Michael wrote:
> Please describe (in code) a situation where two variables share
> the same memory location.
>
Dan you need to try stuff for yourself

#include <stdio.h>

int main(void){
int x=10, *p;
p=&x;
printf("%p, %p\n",(void *)p,(void *)&x);
return 0;
}


You need to think a little harder:

You have two variables: x and p. Are you saying that &x == &p? I sure hope
not.

Try again.


No, of course nobody is saying htat &x == &p.

x and p are undeniably variables. The question is whether *p is also
a variable. If it is, the above program demonstrates a situation
where two variables share the same memory location; if it isn't, it
doesn't.

*p is certainly an object. The question of whether it's also a
"variable" is, in my opinion, a profoundly uninteresting one. The C
standard doesn't define "variable" as a technical term. It uses it
(informally) in a few places. It happens that it uses it only to refer
to declared objects, but we can't really infer anything from that.


*p _may_ be an object. Consider the following:

int *p = NULL;

*p is definitely not an object in this case.

Yes, profoundly uninteresting, but somewhat worthy of senseless never-ending
blather, of which I have been a major (unapologetic) contributor.

Since we are in comp.lang.c* newsgroups, the discussions are not strictly
limited to what the standard does/doesn't define -- such restricted topics are
discussed in comp.std.c*.

Using unions it is possible to declare a variable that shares the same
address. Dereferenced pointers (or references in C++) to a variable are at
most an alias to a variable, but not a variable in terms that I consider
well-defined. Others may (and obviously do, hopefully an informed view)
consider the term 'variable' differently.
Nov 14 '05 #249
Julie <ju***@nospam.c om> writes:
[...]
*p _may_ be an object. Consider the following:

int *p = NULL;

*p is definitely not an object in this case.
Right, but in the example we've been talking about, p has been
assigned the value &x (where x is a declared int object).
Yes, profoundly uninteresting, but somewhat worthy of senseless never-ending
blather, of which I have been a major (unapologetic) contributor.
As have I from time to time.
Since we are in comp.lang.c* newsgroups, the discussions are not
strictly limited to what the standard does/doesn't define -- such
restricted topics are discussed in comp.std.c*.


Actually, comp.lang.c tends to be about the language as defined by the
standard, whereas comp.std.c is about the standard itself. (I just
noticed that this is cross-posted to comp.lang.c++, which is almost
never a good idea.)

[...]

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #250

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

270
3990
by: Jatinder | last post by:
I found these questions on a web site and wish to share with all of u out there,Can SomeOne Solve these Porgramming puzzles. Programming Puzzles Some companies certainly ask for these things. Specially Microsoft. Here are my favorite puzzles. Don't send me emails asking for the solutions.
12
8490
by: G. | last post by:
Hi all, During my degree, BEng (Hons) Electronics and Communications Engineering, we did C programming every year, but I never kept it up, as I had no interest and didn't see the point. But now I really want to get back into it as I see a point with GNU/Linux. I want to get my old skills back and write something or help on some projects etc. I need some good books. I used to have one called "A Book On C", but sold it,
11
2230
by: John Salerno | last post by:
Similar to the Python Challenge, does anyone know of any other websites or books that have programming puzzles to solve? I found a book called "Puzzles for Hackers", but it seems like it might be a little advanced for me, and I've also read that it focuses too much on encryption and security issues and doesn't really have coding problems, exactly. But something like that book would be fun to have.
1
13120
by: xavier vazquez | last post by:
I have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of the other....how i can fix this the program look like this import java.util.ArrayList; import java.util.Random;
0
2031
by: xavier vazquez | last post by:
have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of the other....how i can fix this this run the random words for the program import javax.swing.JOptionPane; import java.util.ArrayList; import java.util.Random; public class CrossWordPuzzleTester {
44
3577
by: Jon Harrop | last post by:
Microsoft Research are developing a functional programming language called F# for .NET and I've been playing with it recently. I've uploaded some demos here: http://www.ffconsultancy.com/dotnet/fsharp/ I'm keen to see what Windows developers think of this language as we're considering using it to develop commercial applications on the Windows platform.
5
4477
by: ashish0799 | last post by:
HI I M ASHISH I WANT ALGORYTHMUS OF THIS PROBLEM Jigsaw puzzles. You would have solved many in your childhood and many people still like it in their old ages also. Now what you have got to do is to solve jigsaw puzzles using the computer. The jigsaw puzzle here is a square of dimension d (a puzzle with d^2 pieces) and the jigsaw pieces (all same dimensions) are of dimensions H x W (Which means the pieces have ‘H’ rows of ‘W’...
3
3213
by: oncue01 | last post by:
Word Puzzle Task You are going to search M words in an N × N puzzle. The words may have been placed in one of the four directions as from (i) left to right (E), (ii) right to left (W), (iii) up to bottom (S), or (iv) bottom to up (N). The program will print the starting place and the direction of each word. Limitations The number of words to be searched can be at most 100, the size of the puzzle N can be minimum 5 maximum 20....
4
20015
by: honey777 | last post by:
Problem: 15 Puzzle This is a common puzzle with a 4x4 playing space with 15 tiles, numbered 1 through 15. One "spot" is always left blank. Here is an example of the puzzle: The goal is to get the tiles in order, 1 through 15, from left to right, top to bottom, by just sliding tiles into the empty square. In this configuration, the goal would be to get the 14 and 15 to switch places, without affecting any of the other squares. Your...
13
3130
by: btkuhn | last post by:
Hi guys, I'm learning Python by teaching myself, and after going through several tutorials I feel like I've learned the basics. Since I'm not taking a class or anything, I've been doing challenges/programs to reinforce the material and improve my skills. I started out with stuff like "Guess my number" games, hangman, etc. and moved on to making poker and card games to work with classes. For GUIs I created games like minesweeper, and a...
0
9855
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10906
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10292
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7017
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4482
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3132
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.