question
Find three ways to modify the code below to print exactly 20 '-' characters by changing or inserting one character.
For this question be sure to check out the hint before the answer!
int i, n = 20;
for (i = 0; i < n; i--)
{
print("-");
}
For this question be sure to check out the hint before the answer!
Here are a few common incorrect solutions.
Changing "n = 20" to "n = -20" will not work
Changing "i--" to "i++" doesn't satisfy the one character condition
Changing "i = 0" to "i = 40" will not work
Changing "i < n" to "i < -n" will not work
Don't view the answer before you have three modifications!
Changing "n = 20" to "n = -20" will not work
Changing "i--" to "i++" doesn't satisfy the one character condition
Changing "i = 0" to "i = 40" will not work
Changing "i < n" to "i < -n" will not work
Don't view the answer before you have three modifications!
Here are three solutions - if you come up with one not listed here, email me to add it!
First solution - change "
Second solution - Change "
Third solution - Change "
First solution - change "
i < n
" to "-i < n
":
int i, n = 20;
for (i = 0; -i < n; i--)
{
print("-");
}
Second solution - Change "
i < n
" to "i + n
":
int i, n = 20;
for (i = 0; i + n; i--)
{
print("-");
}
Third solution - Change "
i--
" to "n--
":
int i, n = 20;
for (i = 0; i < n; n--)
{
print("-");
}