Help!?!?
Your program must contain a function prototype, and the function must be placed below
the main program.
The function must have one parameter, which is used to determine if it is a prime
number.
The function must return a Boolean variable.
The driver program, which is capable of printing the appropriate message whether or not
the number is a prime number.
The second part of the assignment is to create another program that computes all the prime numbers between 1 and the integer n entered by the user. This is giving me alittle trouble.
This is due VERY VERY soon so immediate responses would be appreciated.
Thank you very much.
JHex
Here's what i have so far...
// This program tests whether a number is prime or not
#include <iostream>
using namespace std;
bool isPrime(long);
bool isPrime(long x)
{ long n;
if ( x%2 == 0)
return false;
n = 3;
while (n*n <=x)
{ if (x%n == 0)
return false;
n += 2;
}
return true;
}
int main()
{ long x;
while (1)
{ cout <<"Enter a positive integer to check for primality: ";
cin >> x;
if (isPrime(x))
cout <<x<<" is a prime\n";
else
cout <<x<<" is not a prime\n";
}
}

