Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Question

Reply
Thread Tools

Question

 
 
Venkat
Guest
Posts: n/a
 
      08-26-2004
Hi All,

I have the following problem please help me in solving this.

#include <stdio.h>
main()
{
int i, n=20;
for(i=0;i<n; i--)
{
printf("-");
}
}

Only one character in the above needs to be modified such that the character
'-' will be printed 20 times.
People say there are 3 ways of doing it but i could figure out only one way
given below.

#include <stdio.h>
main()
{
int i, n=20;
for(i=0;i<n; n--)
{
printf("-");
}
}

Can someone crack the other 2 possibilities.


regards,
Venkat





 
Reply With Quote
 
 
 
 
Niels Dybdahl
Guest
Posts: n/a
 
      08-26-2004
> Can someone crack the other 2 possibilities.

Here is one:

for(i=0;-i<n; i--)


 
Reply With Quote
 
 
 
 
Venkat
Guest
Posts: n/a
 
      08-26-2004
"Niels Dybdahl" <> wrote in message
news:412def76$0$182$. ..
> > Can someone crack the other 2 possibilities.

>
> Here is one:
>
> for(i=0;-i<n; i--)
>


Niels thanks for a quick response, the 2nd possibility

is for(i=0;i<n;n--)

we just need the 3rd one.






 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      08-26-2004
Venkat wrote:
> "Niels Dybdahl" <> wrote in message
> news:412def76$0$182$. ..
>
>>>Can someone crack the other 2 possibilities.

>>
>>Here is one:
>>
>>for(i=0;-i<n; i--)
>>

>
>
> Niels thanks for a quick response, the 2nd possibility
>
> is for(i=0;i<n;n--)
>
> we just need the 3rd one.


for(i=0;i+n; i--)

Victor
 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      08-26-2004
"Venkat" <> wrote:
>
> #include <stdio.h>
> main()
> {
> int i, n=20;
> for(i=0;i<n; i--)
> {
> printf("-");
> }
> }
>
> Only one character in the above needs to be modified such that the character
> '-' will be printed 20 times.
> People say there are 3 ways of doing it but i could figure out only one way
> given below.
>
> for(i=0;i<n; n--)


for (i=0;i+n; i--)

PS. I don't think "for (i=0;-i<n; i--)" counts because that is
adding a character, not changing one. Did you quote the original
problem exactly? If it were "for(i=0; i<n; i--)" then you could
change the space to a minus.
 
Reply With Quote
 
Benjamin Dacko
Guest
Posts: n/a
 
      08-26-2004
"Venkat" <> wrote in message news:<1093531576.117124@sj-nntpcache-3>...
> "Niels Dybdahl" <> wrote in message
> news:412def76$0$182$. ..
> > > Can someone crack the other 2 possibilities.

> >
> > Here is one:
> >
> > for(i=0;-i<n; i--)
> >

>
> Niels thanks for a quick response, the 2nd possibility
>
> is for(i=0;i<n;n--)
>
> we just need the 3rd one.


Piece of cake:

#include <stdio.h>
main()
{
int i, n=20;
for(i=0;i+n; i--)
{
printf("-");
}
}
 
Reply With Quote
 
Benjamin Dacko
Guest
Posts: n/a
 
      08-26-2004
"Venkat" <> wrote in message news:<1093531576.117124@sj-nntpcache-3>...
> "Niels Dybdahl" <> wrote in message
> news:412def76$0$182$. ..
> > > Can someone crack the other 2 possibilities.

> >
> > Here is one:
> >
> > for(i=0;-i<n; i--)
> >

>
> Niels thanks for a quick response, the 2nd possibility
>
> is for(i=0;i<n;n--)
>
> we just need the 3rd one.


#include <stdio.h>
main()
{
int i, n=20;
for(i=0;i+n; i--)
{
printf("-");
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57