//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
Recommended Answers
Jump to PostHere is u r answer..
L33t speak is against the rules, and so is giving away free code. Read this.
Now for your code...
void TestPrime(int ); void TestPrime(int n) {
Why is the first line there? You don't have to declare the function if …
Jump to Postat OP: You need nested loops. One that counts from 0-1000 and one that run the first loop 50 times (50 * 1000 = 50000)
Using your own code, it would be something like:
cout << "Start" <<setw(6) << "End" << setw(24) << "Number of Primes\n"; …
All 5 Replies
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.