RSS Forums RSS
Please support our C advertiser: Programming Forums
Views: 1129 | Replies: 7
Reply
Join Date: Mar 2007
Posts: 1
Reputation: mohiuddin.shaik is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mohiuddin.shaik mohiuddin.shaik is offline Offline
Newbie Poster

Solution Changing the meaning of IF else statement

  #1  
Mar 28th, 2007
main()
{
if( ? )
{
printf("welcome");
}
else
{
printf("to ieg");
}
}
-----------------------------------------------------------------------
Output should be
welcome to ieg


what should come in place of ' ? '
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,565
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 977
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Changing the meaning of IF else statement

  #2  
Mar 28th, 2007
any conditional statement that is either true or false. for example if you were asked to enter either 'Y' or 'N' (Yes or No) then the statement might read
if( answer == 'Y')
{
   // true statement
}
else
{
   // false statement
}
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: Feb 2007
Location: Bangalore, India
Posts: 535
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Rep Power: 4
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Changing the meaning of IF else statement

  #3  
Mar 28th, 2007
Originally Posted by Ancient Dragon View Post
any conditional statement that is either true or false. for example if you were asked to enter either 'Y' or 'N' (Yes or No) then the statement might read
if( answer == 'Y')
{
   // true statement
}
else
{
   // false statement
}

Thisnk it's a trick question. May be you didn't read it fully..

@mohiuddin.shaik
It is allowed to write/change anything other than ? e.g. can I use a goto inside the if block?
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,565
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 977
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Changing the meaning of IF else statement

  #4  
Mar 28th, 2007
you are right -- I didn't read the expected outcome, which is impossible. There is no solution that will give that outcome.
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: Feb 2007
Location: Bangalore, India
Posts: 535
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Rep Power: 4
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Changing the meaning of IF else statement

  #5  
Mar 28th, 2007
Originally Posted by Ancient Dragon View Post
you are right -- I didn't read the expected outcome, which is impossible. There is no solution that will give that outcome.

What abt GOTO LABEL?

  1. if ( true )
  2. {
  3. cout << "Hi" << endl ;
  4. goto ELSE_PART ;
  5. }
  6. else
  7. {
  8. ELSE_PART:
  9. cout << " There" << endl ;
  10. }

of course that's cheating but then teh question is not fair..
Last edited by thekashyap : Mar 28th, 2007 at 12:23 pm.
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 7,022
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 25
Solved Threads: 368
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Changing the meaning of IF else statement

  #6  
Mar 28th, 2007
You have just gone out to show one of the horrors of using the GOTO statement in C/C++...
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
Senior Poster

Re: Changing the meaning of IF else statement

  #7  
Mar 28th, 2007
Seems simple enough
int main()
{
    if (!printf("welcome ")) {
        printf("welcome");
    } else {
        printf("to ieg");
    }
    return 0;
}
Reply With Quote  
Join Date: Apr 2006
Location: Canada
Posts: 4,545
Reputation: John A is a name known to all John A is a name known to all John A is a name known to all John A is a name known to all John A is a name known to all John A is a name known to all 
Rep Power: 17
Solved Threads: 284
Moderator
Featured Blogger
John A's Avatar
John A John A is offline Offline
Vampirical Moderator

Re: Changing the meaning of IF else statement

  #8  
Mar 28th, 2007
Originally Posted by Salem View Post
Seems simple enough
int main()
{
    if (!printf("welcome ")) {
        printf("welcome");
    } else {
        printf("to ieg");
    }
    return 0;
}

Wow... Salem! You never fail to impress me... (I'd give you more rep if the system would let me )
tuxation.com - Linux articles, tutorials, and discussions
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:45 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC