GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 416 of 453    Print  
C if condition Puzzle
What's the "condition" so that the following code
snippet prints both HelloWorld !

if "condition"
printf ("Hello");
else
printf("World");



  
Total Answers and Comments: 7 Last Update: April 24, 2009     Asked by: ranjan4unitt 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: mahima.
 
if(!(printf("Hello"))){}elseprintf(" world");

Above answer was rated as good by the following members:
samcorp3, shankysachdeva, adielsa, kmcanil, Jaya_Kaja, rajani_vaddepalli15
June 01, 2008 08:23:31   #1  
mmpcse Member Since: December 2006   Contribution: 1    

RE: C if condition Puzzle
if((printf("Hello") > 0 ? 0 : 1))
printf("Hello");
else
printf("World!n");

if you want World!Hello then change 0 : 1 to 1 : 0

Happy Coding :)

 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
June 06, 2008 12:03:07   #2  
kiranb_rvce Member Since: June 2008   Contribution: 1    

RE: C if condition Puzzle
if ( ! ( printf("Hello ") ) )
printf("Hello");
else
printf("World");

 
Is this answer useful? Yes | NoAnswer is useful 5   Answer is not useful 0Overall Rating: +5    
June 10, 2008 08:00:40   #3  
mahima. Member Since: June 2008   Contribution: 1    

RE: C if condition Puzzle
if(!(printf( Hello ))){}elseprintf( world );
 
Is this answer useful? Yes | NoAnswer is useful 4   Answer is not useful 0Overall Rating: +4    
September 09, 2008 16:11:26   #4  
rashmi.mohanty Member Since: September 2008   Contribution: 8    

RE: C if condition Puzzle
void main(){ if ( ! ( printf("Hello ") ) ) printf("Hello"); else printf("World"); }
 
Is this answer useful? Yes | No
September 15, 2008 05:29:06   #5  
coolquasar Member Since: September 2008   Contribution: 4    

RE: C if condition Puzzle

This will do...

#include<stdio.h>
main()
{
if (!fork())
printf ("Hello");
else
printf("World");
}


 
Is this answer useful? Yes | No
September 18, 2008 21:36:28   #6  
dutta_sudipta Member Since: January 2008   Contribution: 2    

RE: C if condition Puzzle
Is it like this?

void main()
{
int a 2;
while(a--)
if(a)
printf("Hello ");
else
printf("World!");
}

 
Is this answer useful? Yes | No
April 24, 2009 02:14:34   #7  
fazil.vp Member Since: April 2009   Contribution: 1    

RE: C if condition Puzzle
/* Solution 1: */

int main(int argc char* argv[])
{
if( argc 2 || main( 2 NULL ) )
{
printf("Hello ");
}
else
{
printf("Worldn");
}
return 0;
}

/* Solution 2 (Only for Unix and Linux): */

int main(int argc char* argv[])
{
if( !fork() )
{
printf("Hello ");
}
else
{
printf("Worldn");
}
return 0;
}

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape