could you solve this problem?
Someday, Mr. Willy gave me a site that consist of Programming Interview Questions (because our basic was an IT programmer). Lots of challenge cases in there, of course I love it. And I tried to solve some cases too.
This is a simple one, that always made me enthusiastic..
[based on C language programming]
What's the "condition" so that the following code snippet prints both HelloWorld ?
if "condition"
printf ("Hello");
else
printf ("World");
Output : HelloWorld
#include "stdio.h"
ReplyDeletevoid main()
{ if(printf("Hello") && 0)
printf("Hello");
else
printf("World");
}
gee,
ReplyDeletebayu could solve this easily..
actually, lots of our friends can't solve this case
because we didn't think about "function"
Thank you...
ReplyDeletebut I don't know is that the best solution or not, because we just hard code the conditions to printf the word "Hello"...
Not really refer to the statement inside the if block... :P
yeah, i know that :D
ReplyDeleteMr. Nico also solved like that (with PHP), but with OR operator one
if( 0 || printf("Hello") )
remember that PHP had a shortcut method, then
if( 0 || printf("Hello") ) != if( printf("Hello") || 0 )
and my junior, Lina'08, done well too
if( !printf("Hello") )
i think, Lina's code was great....
Actually all have same approach...
ReplyDeletewhenever that function successfully executed, it will return true...
so what we have to do is simply make it become false in order to run the "else" part...
It can be done in many ways... :)
by the way, why don't you follow (back link) my blogspot...??
ReplyDeletehu'uh....
ReplyDeleteafter i understand it, i realized that we never give "this" to our students
what a pity >,<
~~~ sesaaaaat ~~~
(lol)
Actually I gave them this material, especially in programming that involving php.
ReplyDeletewe often use checker function to test a variable exist or not that returning a boolean value. And You already know why, because php doesn't need variable declaration.... :D
if(isset($_SESSION["username"]))
{
/* already logged in */
}
etc....
heihooo, we talk about C, right? :p
ReplyDeletei means, we never give "this" to them in algorithm & programming
do you ever think like this:
*is printf() a function? void or non-void one??
*could we do like this if( printf(..) )?
*then, what is the real result of printf(..)? output in system?? boolean?? others??
hmmmmmm, i must try to be open-minded....
I already know it quite long time ago...
ReplyDeleteI think it is little bit advance for them to dig it deeper in algorithm class..
some of them still confuse whether their custom function return a value or not...
*even it is their own function... they made it by themselves... (-_-!)
but actually they can read it in the help / manual, what built in function are returning value, and return what... :P
yeap, they still don't understand about function itself.. even theirs :P
ReplyDeletehope that i could think like you
because autodidact is not the best way to learn too
sharing could help autodidact's one
whenever you can't find the answer, just ask somebody...
ReplyDeleteIt also part of the learning...
I asked my seniors too in here several times in my self learning...
They are so awesome... :P
i'm just an ordinary person
ReplyDeleteand i've great people around me
lee was very blessed..
Nice...
ReplyDeleteLike indonesia wise word...
Shy to ask, You'll get lost on the road... :P
xixixixi....
ReplyDelete~~~ sesaaat ~~~