GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 416 of 437    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: 6 Last Update: September 18, 2008     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


 
Go To Top


 Sponsored Links

 
Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape