Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Question (http://www.velocityreviews.com/forums/t285235-question.html)

Venkat 08-26-2004 01:50 PM

Question
 
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






Niels Dybdahl 08-26-2004 02:11 PM

Re: Question
 
> Can someone crack the other 2 possibilities.

Here is one:

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



Venkat 08-26-2004 02:42 PM

Re: Question
 
"Niels Dybdahl" <ndy@fjern.detteesko-graphics.com> wrote in message
news:412def76$0$182$edfadb0f@dtext02.news.tele.dk. ..
> > 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.







Victor Bazarov 08-26-2004 03:24 PM

Re: Question
 
Venkat wrote:
> "Niels Dybdahl" <ndy@fjern.detteesko-graphics.com> wrote in message
> news:412def76$0$182$edfadb0f@dtext02.news.tele.dk. ..
>
>>>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

Old Wolf 08-26-2004 09:49 PM

Re: Question
 
"Venkat" <venkat_kp@yahoo.com> 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.

Benjamin Dacko 08-26-2004 11:50 PM

Re: Question
 
"Venkat" <venkat_kp@yahoo.com> wrote in message news:<1093531576.117124@sj-nntpcache-3>...
> "Niels Dybdahl" <ndy@fjern.detteesko-graphics.com> wrote in message
> news:412def76$0$182$edfadb0f@dtext02.news.tele.dk. ..
> > > 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("-");
}
}

Benjamin Dacko 08-26-2004 11:55 PM

Re: Question
 
"Venkat" <venkat_kp@yahoo.com> wrote in message news:<1093531576.117124@sj-nntpcache-3>...
> "Niels Dybdahl" <ndy@fjern.detteesko-graphics.com> wrote in message
> news:412def76$0$182$edfadb0f@dtext02.news.tele.dk. ..
> > > 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("-");
}
}


All times are GMT. The time now is 10:19 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.