Hi, i have written a little script i php, that calculate prime
numbers, and now i want to convert it, so that i can compile it in a
regular c/cpp compiler, but there is severel problems.
1. My skills with c/cpp, is most limited, but i am working on that.
2. In php, i used an array to hold the primes, but, as i have
discovered, it dosnŽt work the same way i c/cpp.
3. It is limited how big numbers the script can handle, and than i am
most enoyed about
3. Then there is a couple of features i would like to have, but i have
no idea how.
1. I would like that all the primes found, is written to a text file.
2. I would also like that the program can be closed, and the later
started again from the point it was at.
3. And at last i would like that the last prime found, and only the
last, apears on the screen while calculating.
And at last, the script i have written i php:
<?
//////////////////////////////////////////////////
// '$pa' = 'Prime Array' - Contains the primes. ///////////////
// '$pp' = 'Potential Prime' - Contains the potential prime. ////////
// '$ip' = 'Is a Prime' - If set to 'false', '$pp' is not a prime. //
/////////////////////////////////////////////////////////////////////
$pa = array (2);
for ($pp = 3; $pp > 0; $pp = $pp + 2) {
$ip = true;
for ($i = 0; $p_a[$i] <= sqrt($pp) && $ip == true ; $i++) {
if ($pp % $p_a[$i] == 0) {
$ip = false;
}
}
if ($ip == true) {
$p_a[] = $pp;
}
}
?>
There is maybe one things that youŽll find odd.
In the first for loop i have used the condition "$pp = 0" and that is
of course, just to make an infinite loop.
Well, to get to the point.
I am not yet qualified to do this stuff, allthou i am working on it,
but never the less, i would wery much like it done, so that i can use
it. So if there is a person who have the time and skills it takes, i
would be glad to see it done.
ANY help and sugestions are welcome...
By the way, sorry about the lousy spelling and stof, but my english is
a little rusty... :)
Thanks in advance...


|