FilChi Weblog

Common programming trick questions

Posted on: December 9, 2006


I am making a post about these usual programming trick questions and give out their solutions because, I really want to show you how simple it could be and advise you that you do not “overthink” it. Oh, I am not giving you exactly in a programming code, but maybe just something like a pseudo-code.
If you have other trick questions that you might want to share, please post it as a comment.

Problems:

1. ) How do you swap two integer values from two variables without using another variable?

2. ) How do you convert an integer ranging from 0 to 999,999,999 to words?

Solutions:

1.

a = a + b;
b= a – b ;
a = a – b ;

2. Note: You’ll have to do this in divisions(functions) to parse a number and convert it to to words. And In each division you have to know if they are in the millions, thousands and ones. (Another Note: I heard from someone that this type of trick question may have a slight variation like, giving out their conversion to Roman Numerals.)

I also tried this in PHP, and you can try the live demo

If(num >=1000000 && num1000 && num1 && num

Advertisements

7 Responses to "Common programming trick questions"

Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru

Run this sample php code and see the output. Can any one explain this kind of behavior of php operators??

// code is here – i think site removed my php tags and script within tags.

$x = “08”;
$y = 08;
$z = ” 47″;

$x +=15;
$y +=”15″;
$z +=11;

echo $x;
echo $y;
echo $z;

// output
231558

Well, more intuitive, and short solution to the first one would be:

list($a, $b) = array($b, $a);

It works with objects too, not only scalars.

if you use that answer Victor:
“Well, more intuitive, and short solution to the first one would be:

list($a, $b) = array($b, $a);

It works with objects too, not only scalars.

You’ll be creating a new variable type “list” so you’re not responding to the questions parameters.

This is really the third article, of your website I personally checked out.
But I really enjoy this specific one, Window Treatments Ideas “Common programming trick questions | FilChi Weblog” the most.

Take care ,Dustin

This is certainly the 3rd article, of your blog I personally
went through. But yet I actually love this one, “Common programming trick questions
| FilChi Weblog” the best. Regards ,Eugenio

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: