• 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
###### 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.

Commented:

Hi mayankeagle,

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

Experts Exchange Solution brought to you by

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

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

2) Hmm..
Commented:
Argh
Congrats.
Commented:
Wow Amit... that was fast and neat

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

-- Amit
Associate 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.
Commented:
Bingo....

Is this Mayank Sarogi

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

But then thought it to be a remote possibility

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

Amit

Associate Director - Product EngineeringAuthor Commented:
>> .... Amit Gupta..... :(

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

Mayank.
Commented:
Definitely Man,

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

Amit
Commented:
one more jus for fun

n= -20
:)
Associate 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.
Commented:
for (i=0; ~i<n ;i--)
try this?

###### 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.