hi all, i m a lil new at this.....so forgive any mistakes here's the riddle : the following appears in a c program: main() { n=20; for(i=0;i<n;i--) printf("-\n"); } now the challenge is to get this code to display 20 dashes i.e 20 ( "-" ) one after the other each on a separate line by doing either one of the following a.appending a SINGLE character from the code. b.deleting a SINGLE character from the code. c.replacing a SINGLE character from the code. note the emphasis on the word single.....lol.......the point is tht only one character may be altered ar added( u get the idea).....and the result upon execution must be 20 dashesone after the other each on a separate line........(as is obvious by the \n in the printf statement) note tht this is for novice programmers only.........u uberhackers can stay out of it!! n if some superprogrammer does give it a try......hebetter come up with a solution in less than 10 sec....lol. o yea and by the way........there's more than one solution to this ........so lets see how many u guys can come up with
Code: for(i=0;i<n;i--) isn't this an infinite loop. but the challenge is now the challenge is to get this code to display 20 dashes i.e 20 ( "-" )
I think, i need little more detail before going for this challenge,as realy i can't understand what's amit challenge
I do not know what is the big deal ... bit I feel assigning n = -20 will fulfill your requirement ... isn't it .. Amit Ray.
or maybe by assigning i = 40 .. in the for loop ... appending one character 4 before the existing 0 ... Amit Ray.
dear amit, i should point out tht if u assign n=-20 then the loop will not be executed at all......isnt it obvious? .if n=-20, then i is no longer less than n (since i is 0). as for ur second suggestion , this too falls flat on its face because of the same reason......i is no longer less than n if n=20 and i=40. perhaps u shouldnt have assumed this problem to be too simple. it is more deceiving than it seems. however i guarantee u there are at leaast 3 solutions to this that i know of. now with this fresh perspective, try and solve the problem again. remember to note down how much time it takes u to solve it. until next time, amit.
oh and by the way, to those of u wondering if im talkin to myself here....i assure u im not. my name happens to be amit too..............jus like amit ray ,our admin. thts me ^ up there talkin to our admin......lol.
this one is for shabbir. dude, the question doesnt not state tht the given loop displays 20 dashes.......neither did i ever suggest or imply in any manner that the loop given as it is in the question is not infinite. read the question. it says display 20 dashes by changing or adding or removing one character........it never says anything about the performance of the original code. the output of the given code as it appears in the question is not to be considered at all........it is the output of the modified code tht is to be worked on. i hope i have cleared all ur doubts. any other queries regarding this problem are most welcome. amitace_223, ace.
this one's for u alok. i personally think the question is complete in itself and is self explanatory. i have tried every bit to ensure that the language is simple ,lucid,concise and to the point. however, i'll try another approach to explain the question. the aim of the question is to get the following output: - - - - - - - - - - - - - - - - - - - - note that this output should be received on the execution of the program by doing only ONE of the following: 1.changing any character in the given program code. 2.adding any character to the given program code. 3.deleting any character from the given program code. i believe this must take care of ur doubt , alok. any other queriesregarding this problem are most welcome. amitace_223, ace.
Eeeeeekks ... well i must be sleeping when i replied .... i mistook the < to be > .. anyways .. changing the for loop to : for (int i=0;-i < n; i--) would be one answer ... ( hoping u did not miss out declaring 'i' intentionally ... ) .. as for the other possibilities .. maybe later .. Amit Ray.
So here are the three other solutions I can think of Code: for (int i=0;i + n; i--) Code: for (int i=0;-i < n; n--) Code: for (int i=40;i < n; i--) Thanks Shabbir Bhimani
Hi all experts out there .... need some ...new to programming.. below is the program for which i need to know the the process....I know the aswer which is = 9.....but need to know how come... what is the calculation. Consider the following program segment: i = 6720; j = 4; WHILE ( (i % j) = = 0){ i = i / j; j = j + 1; } plz help...need it asap. thanks & regards, carl carl.banderas@rediffmail.com