Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Leda > Conversion - PH...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 120 of 212
Post > Topic >>

Conversion - PHP2C, and a little more...

by felixnielsen@[EMAIL PROTECTED] (Felix Nielsen) Apr 4, 2004 at 06:38 PM

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...




 1 Posts in Topic:
Conversion - PHP2C, and a little more...
felixnielsen@[EMAIL PROTE  2004-04-04 18:38:57 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 11:06:41 CDT 2008.