i have this hw question where i have to find all prime numbers between 1-1000 using boolean i.e.
bool primeNum (long num);
and then displays it and sums up all the prime numbers.
i have problems just finding all prime numbers, it ended up finishing at "number 1 is a prime number"
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
bool isPrimeNumber;
double root,num,a;
a=1;
num=1;
root=num/sqrt(num);
do{
if (root==sqrt(num))
{
cout << "The number " << num << " is a prime number";
bool isPrimeNumber = true;
}
else if (root!=sqrt(num))
{
bool isPrimeNumber = false;
}
num++;
}
while (num<=1000);
system ("pause");
return 0;
}
how can i keep it going, ive re-done this part of the question many times with the same problem; not getting to loop to 1000. I'm not sure i understand using Boolean clearly either.
a number is prime if it is not divisible by any other number except 1 and itself
so
1) take a number say N
2) start from 2 till N/2 and see when divided any of the remainder is zero
3) if any where the remainder is zero then that no is not prime
4) else the no is prime
I guess my issue is how i can keep it displaying prime numbers all the way to the limit 1000, atm it just stops at "The number 1 is a prime numberPress any key to continue" when i compile it.
using Bloodshed Dev-C++ IDE 4.9.9.2.