I thought it would be fun to take a programming. I have no prior experience with this kind of stuff and it turns out I’m really bad at it.
I was given a project were I had to make a program that can list all of the prime numbers between two and any random number.
this is all I’ve managed to do.
Page 1
[php]<?php
$MAX = 0; // HIGHEST VALUE COMES FROM THE SCREEN //
$X = 3; // COUNTER //
$FLAG = TRUE; //DETEMINES WHETHER PRIME OR NOT, TRUE=PRIME//
$R = 0; // REMAINDER //
$I = 2; // MOD //
//PROMPT MAX
//GET MAX
?>[/php]
Page 2
[php]<?php
$MAX = 0; // HIGHEST VALUE COMES FROM THE SCREEN //
$X = 3; // COUNTER //
$FLAG = TRUE; //DETEMINES WHETHER PRIME OR NOT, TRUE=PRIME//
$R = 0; // REMAINDER //
$I = 2;
ECHO “2 is a prime number”;
IF($MAX==“1”) //THEN
$FLAG=FALSE;
//ENDIF;
WHILE($X<=$MAX) // EVAL EVERY NO FROM X TO MAX //
$I=2;
WHILE($I<$X)
$R=$X%$I;
IF($R==0) //THEN
$I=$X;
$FLAG=FALSE; // AT THIS POINT NOT PRIME //
//ENDIF
($I++);
//ENDWHILE // I < X //
If($flag=TRUE);
ECHO “$X IS PRIME”;
$X++ ;
//ENDWHILE // X < MAX //
?>[/php]
When I run it it says “Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\xampp\hw3p2.php on line 26”. Line 26 is where it says WHILE($I<$X).
I know this is some really sloppy and amateur, but any help I can get to make it work would be greatly appreciated.