Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*6.29
- Deitel & Deitel C++ How to Program, 10th ed(Indian subcontinent adaptation)
- Visual Studio Community 2019 */
- #include <iostream>
- #include <cmath>
- using namespace std;
- bool isPrime(int testNum) {
- if ( testNum == 2 ) return true;
- if (testNum % 2 == 0) return false;
- for (int divisor = 2; divisor <= sqrt(testNum); divisor++) {
- if (testNum % divisor == 0) return false;
- }
- return true;
- }
- int main() {
- int count{ 0 };
- for (int i{ 2 }; i <= 10000; i++) {
- if (isPrime(i)) {
- cout << i << " is prime." << endl;
- count++;
- }
- }
- cout << "Total Number of primes from 1 to 10,000: " << count;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment