0
What is my error in this code for the challenge Multiple?
The output for the input '100' is supposed to be '2318' but I get '2418'. Here is my code https://code.sololearn.com/cH0hCy0LU5IE/?ref=app
15 Réponses
+ 4
A͢J
But how does it change the output of 100 that much?
edit: now I understand... it's cause in the explanations, it says, every number below the number that is inputed so 100 in not included.
+ 2
eloufou
As index starts from 0 so for loop should work till < only
So for (int i = 0; i < 100; i++)
if you include 100 then output is 2418
Btw why not to use modulus (%)
https://code.sololearn.com/cYuo17n3vQ6Q/?ref=app
+ 1
eloufou
Because of i <= tNumber
+ 1
eloufou
Why 101 if (i <= 100)
+ 1
eloufou
101 < 100 is false
99 < 100 is true
So i < 100 will stop at 99 not 101
+ 1
eloufou
101 <= 100 is false
100 <= 100 is true
So i <= 100 will stop at 100
+ 1
eloufou
use long long instead of double long
Check my code and enter 4242
+ 1
eloufou yes
0
A͢J
What does it changes in the logic?
0
A͢J
So 101 will be include in the loop?
0
A͢J
Sry... my bad, I'm just lost asf
0
A͢J
Now when the input number is 4242, the output need to be 4198308 but I get an exponential number... can you explain the error if it's not too big of a request?
0
A͢J
It can handle more bits? Am I right?
0
A͢J
Alright, all good for this question
I sended my last question in private chat...
- 1
A͢J
(I < 100) will stop at 101
(I <= 100) will stop at 100
edit: I am I just lost?