• C

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.
LVL 30
Mayank SAssociate Director - Product EngineeringAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andrewjbCommented:
1) for ( i = 0 ; i < n; i -- )

2) Hmm..
0
andrewjbCommented:
Argh
Congrats.
0
The Lifecycle Approach to Managing Security Policy

Managing application connectivity and security policies can be achieved more effectively when following a framework that automates repeatable processes and ensures that the right activities are performed in the right order.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.