+ 5

What's wrong with the code? I just can't seem to figure it out.

https://code.sololearn.com/c7LvfLJP43l9/?ref=app

12th Feb 2020, 2:04 PM
sTiNgRaY
sTiNgRaY - avatar
26 Respuestas
+ 10
Your code does not really calculate primes. A number N is a prime number if it has only 2 divisors (without giving a remainder): 1 and N itself. To implement a very basic calculation, you have to take the input number N, and dived it in a loop by all numbers from 2 up to N. If N can be divided evenly without a remainder by one of these values, it is not a prime number. If it can not be divided without a remainder it is a prime value.
12th Feb 2020, 4:39 PM
Lothar
Lothar - avatar
+ 8
okay... there are two probs in your code 1. no loop 2. to check if x is devisible by i ist tested by x%i == 0 not too much work to do go on. 👍
12th Feb 2020, 4:34 PM
Oma Falk
Oma Falk - avatar
+ 5
Lothar I think he will make it. Have a good feeling.
12th Feb 2020, 4:52 PM
Oma Falk
Oma Falk - avatar
+ 4
at least a loop is missing. I dont understand your algorithm idea please explain for input 5
12th Feb 2020, 4:26 PM
Oma Falk
Oma Falk - avatar
+ 3
In your last version all numbers, including primes, will be shown as composite. (yes, i did link a code from a total different task here, but i deleted it a minute later - sorry for this!)
12th Feb 2020, 6:39 PM
Lothar
Lothar - avatar
+ 3
sTiNgRaY better and better
12th Feb 2020, 6:47 PM
Oma Falk
Oma Falk - avatar
+ 3
👍👍👍but 2 is a special caseLothar we give him an A?
12th Feb 2020, 7:25 PM
Oma Falk
Oma Falk - avatar
+ 2
Thanks a lot! I'll update the code and see if it works 👍
12th Feb 2020, 4:35 PM
sTiNgRaY
sTiNgRaY - avatar
+ 2
No idea how to do that Oma Falk . I've done only the first two modules as of now and have no practice at all.
12th Feb 2020, 7:39 PM
sTiNgRaY
sTiNgRaY - avatar
+ 2
If you're looking for coding puzzles, there are lots in the "community challenge" section under the "Learn" tab of the home page. This Android app has quite a lot: https://play.google.com/store/apps/details?id=com.alansa.ideabag2I
14th Feb 2020, 3:54 AM
David Ashton
David Ashton - avatar
+ 1
I'm trying to do a loop which checks if x is divisible by at least one value of i so that it is composite.
12th Feb 2020, 4:31 PM
sTiNgRaY
sTiNgRaY - avatar
+ 1
I tried but still can't work it out.
12th Feb 2020, 4:37 PM
sTiNgRaY
sTiNgRaY - avatar
+ 1
Thank you! That made it clearer. I'll edit it and make it work
12th Feb 2020, 4:41 PM
sTiNgRaY
sTiNgRaY - avatar
+ 1
Thanks a lot guys! I've updated it and it now works! Please do test it if you want and let me know! Lothar Oma Falk
12th Feb 2020, 6:04 PM
sTiNgRaY
sTiNgRaY - avatar
+ 1
Did you link the wrong code by mistake?
12th Feb 2020, 6:28 PM
sTiNgRaY
sTiNgRaY - avatar
+ 1
It is finally done! It now works flawlessly! Please do check it out and let me know if there are any further mistakes to be corrected! Thank you a lot for your feedback! This is what keeps me going and helps a lot!
12th Feb 2020, 7:21 PM
sTiNgRaY
sTiNgRaY - avatar
+ 1
Thanks a ton! Tell me if you have some projects for beginners. Looking forward to it. Also, 2 works now as well!
12th Feb 2020, 7:26 PM
sTiNgRaY
sTiNgRaY - avatar
12th Feb 2020, 7:28 PM
Oma Falk
Oma Falk - avatar
+ 1
YOU laZY GUY WOULD YOU MIND USING YOUR BRAIN PLEEEEEAÀAASE 3😤😤
12th Feb 2020, 7:41 PM
Oma Falk
Oma Falk - avatar
+ 1
🤣🤣🤣 now....try it later Primes were not so bad.
12th Feb 2020, 7:43 PM
Oma Falk
Oma Falk - avatar