Primes Calc | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Primes Calc

How can i find the all primes less than number 'n'? https://code.sololearn.com/cs16oBO8dMVg/?ref=app

22nd Oct 2017, 7:54 PM
Emin Keresteci
Emin Keresteci - avatar
2 Answers
+ 2
you save every prime you find and a prime is a number which is not divideable by any prime number before so if n is bigger then 2 you add 2 to your primearray. now for every number till n you iterate over your primearray and check if the current number modulo every number in the array is >0 if this is true you add the number to your prime array if not you take the next number and do the same... ! do not add 1 to the prime array but dont forget to print it for completion
24th Oct 2017, 10:31 AM
Chrizzhigh
Chrizzhigh - avatar
+ 2
I have solved the problem in my code. Thank you for your attention.
24th Oct 2017, 10:51 AM
Emin Keresteci
Emin Keresteci - avatar