I need help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I need help

Why does this code not work with numbers that are the product of more than 7 numbers? For instance, insert 128 and it will be factorised successfully. But, insert 256 and it won't. This does not make sense at all to me and I spent such 2 hours today just trying to figure out what's wrong with this code. I'd love anyone to please answer me https://code.sololearn.com/cxDn6LdB0gAs/?ref=app

18th Oct 2018, 5:53 PM
Filippo Passante
Filippo Passante - avatar
3 Answers
+ 1
Are you sure you know how an array works? : c = 1, fact[c] Later in the code you try to access elements after index 0, that's not going to fly. Changing the array to an initial size of 100 for example fixes the code. If you want a resizeable array you should look into std::vector.
18th Oct 2018, 6:53 PM
Dennis
Dennis - avatar
+ 1
Bad luck, it just appears to work for prime factors that are less than 8. It's probably because the memory you write to just happen to not get overridden, but it could happen at any moment. It depends on how the compiler decides on how to lay out the memory and any possible optimizations applied.
21st Oct 2018, 11:07 AM
Dennis
Dennis - avatar
0
So why does it work for those numbers whose prime factors are less than 8?
21st Oct 2018, 10:58 AM
Filippo Passante
Filippo Passante - avatar