• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

Puzzle for friends (and everyone :-) )

Hi all,

Well, this is a simple for loop (of course, which doesn't do anything specific!). Let's see if we can make it different.

int i, n = 20 ;
for ( i = 0 ; i < n; i -- )
  printf ( "-" ) ;

The problem is to make this for loop print the "-" exactly 20 times by either replacing, or adding or removing only a single character from the code. There are three solutions to the above problem.

By the way, Kocil, Akshay, haven't seen you guys around since a long while (matter of factly, I haven't been around much myself in the last few days. Am posting more on the Java forum now.) This is just an attempt to say Hi to all of you after a long time....

Anyways, everyone's welcome to answer. Let's see who gets all three correct solutions first!

Mayank.
0
Mayank S
Asked:
Mayank S
  • 5
  • 4
  • 2
  • +3
1 Solution
 
Sys_ProgCommented:

Hi mayankeagle,

Here is the answer

1] Replace i by n in for loop.
   for ( i=0;i<n; n--)
2] Replace i by -i in the for loop.
   for (i=0; -i<n ;i--)
3] Replace < by + in the for loop.
   for ( i=0; i+ n; i-- )

Thanks

Amit
0
 
andrewjbCommented:
1) for ( i = 0 ; i < n; i -- )

2) Hmm..
0
 
andrewjbCommented:
Argh
Congrats.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sunnycoderCommented:
Wow Amit... that was fast and neat

welcome back mayank.. hope we will see more of you in coming days
0
 
Sys_ProgCommented:
Thanks Sunny

-- Amit
0
 
Mayank SAssociate Director - Product EngineeringAuthor Commented:
Well, that was definitely quick. I guess he answered it within 8 minutes of my asking the question.... just out of curiosity, are you Amit Gupta?

BTW, thanks, Sunny. Hope I will be around more frequenlty now.

Mayank.
0
 
Sys_ProgCommented:
Bingo....

Is this Mayank Sarogi

--Amit Gupta
0
 
Mayank SAssociate Director - Product EngineeringAuthor Commented:
Nopes,  sorry. I guess you're some other Amit Gupta :-) I'm Mayank Shridhar.
0
 
Sys_ProgCommented:
That's a great coincidence.

Actually I did had a look at your profile (after answering) when I looked at your login-name and had a slight blink in mind about one of my college friend - mayank
But then thought it to be a remote possibility

Anyways, that also shows the abundance of people named Amit Gupta.....:(    

Amit





0
 
Mayank SAssociate Director - Product EngineeringAuthor Commented:
>> .... Amit Gupta..... :(    

What's so sad about that?

Anyways, I guess I earned one more friend through this :-) See you around....

Mayank.
0
 
Sys_ProgCommented:
Definitely Man,

I would love to have friends like u......   :)

Amit
0
 
applekannaCommented:
one more jus for fun

n= -20
:)
0
 
Mayank SAssociate Director - Product EngineeringAuthor Commented:
Nopes, in that case, control won't go into the for loop at all as ( i < n ) is not satisfied initially.
0
 
chikucoderCommented:
for (i=0; ~i<n ;i--)
try this?


 
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 4
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now