| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Venkat" |
| Date: |
26 Aug 2004 08:50:59 AM |
| Object: |
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
.
|
|
| User: "Old Wolf" |
|
| Title: Re: Question |
26 Aug 2004 04:49:31 PM |
|
|
"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.
.
|
|
|
|
| User: "Niels Dybdahl" |
|
| Title: Re: Question |
26 Aug 2004 09:11:02 AM |
|
|
Can someone crack the other 2 possibilities.
Here is one:
for(i=0;-i<n; i--)
.
|
|
|
| User: "Venkat" |
|
| Title: Re: Question |
26 Aug 2004 09:42:20 AM |
|
|
"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.
.
|
|
|
| User: "Benjamin Dacko" |
|
| Title: Re: Question |
26 Aug 2004 06:55:56 PM |
|
|
"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("-");
}
}
.
|
|
|
|
| User: "Benjamin Dacko" |
|
| Title: Re: Question |
26 Aug 2004 06:50:06 PM |
|
|
"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("-");
}
}
.
|
|
|
|
| User: "Victor Bazarov" |
|
| Title: Re: Question |
26 Aug 2004 10:24:43 AM |
|
|
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
.
|
|
|
|
|
|

|
Related Articles |
|
|