Why the output are 2p 4p 6p 8p? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why the output are 2p 4p 6p 8p?

I want to know how to calculate it and how loop work. how should I do? s<=3*x-1 s<=3*1-1=2 p s<=3*2-1=5 p s<=3*3-1=8 p s<=3*4-1=11 p What's wrong with my calculation? Please help me!! https://code.sololearn.com/c6UP04Tt61Mv/?ref=app

21st May 2018, 6:45 PM
Mr Thaw
Mr Thaw - avatar
2 Answers
+ 10
lol I didn't expect you to actually move the post. I typed my whole answer and the comment was gone 😢 ANYWAY. for (y = x; y <= 3; y++) //Inner for That condition is the formula that determines how many p's are printed. It works like this, for n letters every loop: (n + 1) * x - 1 Ex: If you want 5 letters every loop, your formula should be: 6 * x - 1 For 1 letter every loop (which I think is what you want to do), use this: 2 * x - 1
21st May 2018, 7:15 PM
Tamra
Tamra - avatar
+ 2
You are doing 3*x-x p since you start at x
21st May 2018, 7:00 PM
Max
Max - avatar