Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Puzzle for friends (and everyone :-) )

Posted on 2003-12-12
14
Medium Priority
?
375 Views
Last Modified: 2010-04-15
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
Comment
Question by:Mayank S
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +3
14 Comments
 
LVL 10

Accepted Solution

by:
Sys_Prog earned 200 total points
ID: 9926997

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
 
LVL 12

Expert Comment

by:andrewjb
ID: 9927048
1) for ( i = 0 ; i < n; i -- )

2) Hmm..
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9927051
Argh
Congrats.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 45

Expert Comment

by:sunnycoder
ID: 9927120
Wow Amit... that was fast and neat

welcome back mayank.. hope we will see more of you in coming days
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9927157
Thanks Sunny

-- Amit
0
 
LVL 30

Author Comment

by:Mayank S
ID: 9927262
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
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9927300
Bingo....

Is this Mayank Sarogi

--Amit Gupta
0
 
LVL 30

Author Comment

by:Mayank S
ID: 9927355
Nopes,  sorry. I guess you're some other Amit Gupta :-) I'm Mayank Shridhar.
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9927392
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
 
LVL 30

Author Comment

by:Mayank S
ID: 9927684
>> .... Amit Gupta..... :(    

What's so sad about that?

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

Mayank.
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9928124
Definitely Man,

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

Amit
0
 
LVL 3

Expert Comment

by:applekanna
ID: 9948047
one more jus for fun

n= -20
:)
0
 
LVL 30

Author Comment

by:Mayank S
ID: 9948309
Nopes, in that case, control won't go into the for loop at all as ( i < n ) is not satisfied initially.
0
 
LVL 1

Expert Comment

by:chikucoder
ID: 9948452
for (i=0; ~i<n ;i--)
try this?


 
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question