+5

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

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

2/12/2020 2:04:18 PM

sTiNgRaY

26 Answers

New Answer

+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.

+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. 👍

+5

Lothar I think he will make it. Have a good feeling.

+4

at least a loop is missing. I dont understand your algorithm idea please explain for input 5

+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!)

+3

sTiNgRaY better and better

+3

👍👍👍but 2 is a special caseLothar we give him an A?

+2

Thanks a lot! I'll update the code and see if it works 👍

+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.

+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.

+1

I tried but still can't work it out.

+1

Thank you! That made it clearer. I'll edit it and make it work

+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

+1

Did you link the wrong code by mistake?

+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!

+1

Thanks a ton! Tell me if you have some projects for beginners. Looking forward to it. Also, 2 works now as well!

+1

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

+1

YOU laZY GUY WOULD YOU MIND USING YOUR BRAIN PLEEEEEAÀAASE 3😤😤

+1

🤣🤣🤣 now....try it later Primes were not so bad.

+1

I'll try it later for sure 👍. It's 1:30 am so tomorrow morning.