//I have a problem, i trying to get the total prime numbers for each row on the output.
//I jus getting the total prime numbers from the firs line 1 to 100
// my task is to get the total prime number from 1 to 100, 1001 to 2000.....49001 to 5000
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
bool find_prime(long);
//long primeCount (long x, long y);
int main ()
{
int i, counter =0;
bool test;
for (i =1; i < 1000; i++ )
{
test = find_prime(i);
if ( test == true )
{
counter++;
}
}
cout << "Start" <<setw(6) << "End" << setw(24) << "Number of Primes" << endl;
for (i; i <= 50000; i = i + 1000)
{
cout << i-999 <<setw(10) << i << setw(11) << counter << endl;
}
cout << "Total primes in the first 50 chiliads:" << counter << endl;
cout << "Average number per chiliad:" << counter/1 << endl;
system("pause");
}
bool find_prime (long num)
{
int j;
if(num <= 1)
return false;
for ( j = 2; j*j <= num; j++ )
if (num%j == 0)
return false;
return true;
}
purepecha -6 Newbie Poster
Aamit -7 Posting Whiz
Aamit -7 Posting Whiz
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
Prabakar 77 Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.