0

How to make an operation to count prime number less than 100000 base on the following given code?

Here is the given code: #include <iostream> using namespace std; int main() { int n; cin 》 n; cout 《 prime_smaller_than (n); } I dont know anything about prime check because its just only been 6 days of my c++ knowledge. How can you do it in a similar but not different than the style of code above. Many thanks.

3rd Mar 2017, 9:30 AM
Vince Gynesse
Vince Gynesse - avatar
1 Respuesta
0
the prime number is just a number which cannot be devided by other than 1 and itself. its a math thing, not a C++ thing. there are some shortcuts for cheching that, but you can check if the rest of the division is not zero for all numbers smaller than the number to checked, except for 1 and itself. eg. none of 7%2, 7%3, 7%4, 7%5 and 7%6 is zero, so 7 is prime. if any of these returns zero than it is not prime.
3rd Mar 2017, 11:11 AM
Kleber Leal
Kleber Leal - avatar