473,839 Members | 1,519 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
Alex Monjushko wrote:
Not necessarily. Consider the following, in the same translation unit.

static int a = 42;

extern int a; /* deceptive use of 'extern' */

As I had said for this one later in the message:

"extern int k; means that it is defined elsewhere (in general)"


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Nov 14 '05 #261
In comp.lang.c Ioannis Vranos <iv*@guesswh.at .grad.com> wrote:
Alex Monjushko wrote:
Not necessarily. Consider the following, in the same translation unit.

static int a = 42;

extern int a; /* deceptive use of 'extern' */


As I had said for this one later in the message: "extern int k; means that it is defined elsewhere (in general)"


"Elsewhere" is technically correct, but it is a little vague in light
of your initial reference to separate translation units.

--
Alex Monjushko (mo*******@hotm ail.com)
Nov 14 '05 #262
Alex Monjushko wrote:
In comp.lang.c Ioannis Vranos <iv*@guesswh.at .grad.com> wrote:
Alex Monjushko wrote:


Not necessarily. Consider the following, in the same translation unit.

static int a = 42;

extern int a; /* deceptive use of 'extern' */

As I had said for this one later in the message:


"extern int k; means that it is defined elsewhere (in general)"

"Elsewhere" is technically correct, but it is a little vague in light
of your initial reference to separate translation units.


Ok, OK! :-)


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Nov 14 '05 #263
Keith Thompson wrote:

This is posted only to comp.lang.c++, which I don't regularly follow.

Julie <ju***@nospam.c om> writes:
Ioannis Vranos wrote: [...]
The C++ standard says: [...] "A variable is introduced by the declaration of an object. The
variable's name denotes the object."


Fine -- but what that is saying is that when you create an object, you also
introduce a variable. The opposite is not necessarily true: introducing a
variable does *NOT* imply the declaration of an object.


The first occurence of "variable" in the above quotation from the
standard is in italics. That means it's the definition of the word
"variable", which implies that it's exclusive, i.e., that anything not
introduced by the declaration of an object is not a variable.


You may want to research predicate logic.
That may or may not match the common usage of the term, but if that's
what the standard says it seems appropriate to stick to that
definition.

(The C standard, on the other hand, doesn't define the word
"variable", which is why I dropped comp.lang.c from the Newsgroups
header.)


Again, this discussion doesn't have to limit itself to what is or is not
included in any standard. This discussion is about languages, in a forum about
languages (comp.lang.c*), as defined about standards. Variable discussions in
comp.std.c may be inappropriate, here in comp.lang.c, it is perfectly
appropriate -- I've re-added the newsgroup to this reply.
Nov 14 '05 #264
Ioannis Vranos wrote:
Alex Monjushko wrote:
In comp.lang.c Ioannis Vranos <iv*@guesswh.at .grad.com> wrote:
Alex Monjushko wrote:

Not necessarily. Consider the following, in the same translation unit.

static int a = 42;
extern int a; /* deceptive use of 'extern' */


As I had said for this one later in the message:

"extern int k; means that it is defined elsewhere (in general)"


"Elsewhere" is technically correct, but it is a little vague in light
of your initial reference to separate translation units.



Ok, OK! :-)

Also extern int k; can be a definition by itself in the absence of any
other definition.


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Nov 14 '05 #265
Julie wrote:
Again, this discussion doesn't have to limit itself to what is or is not
included in any standard. This discussion is about languages, in a forum about
languages (comp.lang.c*), as defined about standards. Variable discussions in
comp.std.c may be inappropriate, here in comp.lang.c, it is perfectly
appropriate -- I've re-added the newsgroup to this reply.

Yes it is about the language as defined by the standard, so we should be
better stick to the terminology of the standard, if for not other reason
to be able to understand one another.

clc on the other hand is another language so by adding other languages
newsgroups can only add more confusion.


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Nov 14 '05 #266
Ioannis Vranos wrote:
Yes it is about the language as defined by the standard, so we should be
better stick to the terminology of the standard, if for not other reason
to be able to understand one another.

clc on the other hand is another language

newsgroup

so by adding other languages
newsgroups can only add more confusion.



Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Nov 14 '05 #267
Ioannis Vranos wrote:

Julie wrote:
"A variable is introduced by the declaration of an object. The
variable’s name denotes the object."

Fine -- but what that is saying is that when you create an object, you also
introduce a variable. The opposite is not necessarily true: introducing a
variable does *NOT* imply the declaration of an object.


No it says that you declare an object by using a variable. So when you
"declare" a variable in essence you declare an object.


It doesn't say that or infer that at all. Research predicate logic. You can't
assume the reverse of an inference is true.

Specifically:

'declaration of an object' implies 'variable is introduced' (always true)

cannot be reversed to:

'variable is introduced' implies 'declaration of an object' (conditionally
true)
If that is the extent of what is discussed in the standard, then the short of
it is that the standard does not define what a variable is.


It does. A variable (its name) denotes an object.
"An object is a region of storage. [Note: A function is not an object,
regardless of whether or not it occupies storage in the way that objects
do. ] An object is created by a definition (3.1), by a new-expression
(5.3.4) or by the implementation (12.2) when needed."

Seems like it isn't complete to me. Either the other ways (C-style?) to
instanciate an 'object' are either implied or just plain left out. Consider
the differences between:

int i; // created by a definition

int * j = new int; // by a new-expression

extern int k; // by the implementation


Actually defined in another compilation unit.


So what? I was giving an example of the something 'created ... by the
implementation' , presuming that k is part of the implementation.
int * l = (int *)malloc(sizeof (int)); // what about me?


In the above cases we have:

int i;

i is a variable that denotes an object.

int *j=new int;

j is a variable that denotes an int * object, that is the pointer itself.

The new int that is created in the free store is another object, not
denoted by a variable, since it is not created by a variable declaration.

extern int k; means that it is defined elsewhere (in general) and the
"int i" case applies for the definition.

The malloc() situation is the same with the new int situation.


Not the same, but similar, and *not* included in the standard text that you
quoted. That was my point -- the standard text is incomplete, or your
quote/reference is.
Nov 14 '05 #268
Julie wrote:
It doesn't say that or infer that at all. Research predicate logic. You can't
assume the reverse of an inference is true.

Specifically:

'declaration of an object' implies 'variable is introduced' (always true)

cannot be reversed to:

'variable is introduced' implies 'declaration of an object' (conditionally
true)


Ok. You may continue wasting your energy in endless discussions. :-)

The malloc() situation is the same with the new int situation.

Not the same, but similar, and *not* included in the standard text that you
quoted. That was my point -- the standard text is incomplete, or your
quote/reference is.


What do you mean not included. It is the same case with operator new.


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Nov 14 '05 #269
Ioannis Vranos wrote:

Julie wrote:
It doesn't say that or infer that at all. Research predicate logic. You can't
assume the reverse of an inference is true.

Specifically:

'declaration of an object' implies 'variable is introduced' (always true)

cannot be reversed to:

'variable is introduced' implies 'declaration of an object' (conditionally
true)


Ok. You may continue wasting your energy in endless discussions. :-)


I'm getting close to being out of energy on this discussion...
Nov 14 '05 #270

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
10585
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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...
0
5866
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.