Program to calculate prime numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Program to calculate prime numbers

24th Nov 2016, 5:27 PM
Kareem Mohamed
Kareem Mohamed - avatar
2 Answers
+ 1
This code would help you to identify if a number is prime. To calculate a set of prime number use a loop (for..) and print only the values returned true by isPrime(). bool isPrime(int x) { if (x<=0) return false; // i don't test those values if (x<2) return true; // 1 and 2 are primes! for (int i=2;i<x;i++) { if (x%i==0) return false; } return true; } Please take a look to my code: https://code.sololearn.com/c8gjJwr0o455/?ref=app
25th Dec 2016, 12:35 AM
Michael Isac Girardi
Michael Isac Girardi - avatar
0
do by yourself...for(i=2;i<10;I++) if(number%i==0) count++;
24th Nov 2016, 5:57 PM
somnath
somnath - avatar