Question

V

Venkat

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
 
O

Old Wolf

Venkat said:
#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.
 
B

Benjamin Dacko

Venkat said:
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("-");
}
}
 
B

Benjamin Dacko

Venkat said:
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("-");
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top