C Problem - Interestin puzzle

Pages: 1, 2
free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

C Problem - Interestin puzzle

sunilr_74
QUOTE(cse-icons @ Oct 20 2004, 08:34 PM)
int i, n = 20;
for (i = 0; i < n; i--)
printf("-");


You have to print '-' 20 times. by adding or removing or replacing only
a single character from the code.
There are 3 possible solutions for the above question. Can u get them?
*



here goes:
1. replace i with n in the for() loop
2. make it -i < n
3. in for() loop init i as 40 (for(i=40;i < 20 ... )

so there :-)

Reply

rowita
sunilr no.3 is not correct!

cse_icons , you sure there's another way!?

Reply

cse-icons
yeah, there are 3 solutions all-right...

i will post all the solutions in my next reply... got to go now....

bye....

Reply

cse-icons
hi all,

here are the 3 solutions, in case you still want to give it a try.. dont look at the solutions below:













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



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



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

Reply

rowita
Good Logical solution in third method
i like that , thanks

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Similar Topics

Keywords : interestin puzzle


    Looking for c, problem, interestin, puzzle

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for c, problem, interestin, puzzle

*MORE FROM TRAP17.COM*
advertisement



C Problem - Interestin puzzle



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE