What is my error in this code for the challenge Multiple? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

15th Aug 2022, 1:46 AM
eloufou
eloufou - avatar
15 Answers
+ 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.
15th Aug 2022, 4:04 AM
eloufou
eloufou - avatar
+ 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
15th Aug 2022, 3:51 AM
A͢J
A͢J - avatar
+ 1
eloufou Because of i <= tNumber
15th Aug 2022, 3:47 AM
A͢J
A͢J - avatar
+ 1
eloufou Why 101 if (i <= 100)
15th Aug 2022, 3:58 AM
A͢J
A͢J - avatar
+ 1
eloufou 101 < 100 is false 99 < 100 is true So i < 100 will stop at 99 not 101
15th Aug 2022, 4:02 AM
A͢J
A͢J - avatar
+ 1
eloufou 101 <= 100 is false 100 <= 100 is true So i <= 100 will stop at 100
15th Aug 2022, 4:03 AM
A͢J
A͢J - avatar
+ 1
eloufou use long long instead of double long Check my code and enter 4242
15th Aug 2022, 4:19 AM
A͢J
A͢J - avatar
+ 1
15th Aug 2022, 4:35 AM
A͢J
A͢J - avatar
0
A͢J What does it changes in the logic?
15th Aug 2022, 3:49 AM
eloufou
eloufou - avatar
0
A͢J So 101 will be include in the loop?
15th Aug 2022, 3:57 AM
eloufou
eloufou - avatar
0
A͢J Sry... my bad, I'm just lost asf
15th Aug 2022, 4:02 AM
eloufou
eloufou - avatar
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?
15th Aug 2022, 4:09 AM
eloufou
eloufou - avatar
0
A͢J It can handle more bits? Am I right?
15th Aug 2022, 4:21 AM
eloufou
eloufou - avatar
0
A͢J Alright, all good for this question I sended my last question in private chat...
15th Aug 2022, 4:38 AM
eloufou
eloufou - avatar
- 1
A͢J (I < 100) will stop at 101 (I <= 100) will stop at 100 edit: I am I just lost?
15th Aug 2022, 4:00 AM
eloufou
eloufou - avatar