Pastebin

New pastes are no longer accepted · Stats

Latest Pastes

factorialsphp

<html>
<head>
<title>Factorial Ting</title>
</head>
<body>
<?php
	if(isset($_GET["n"])){
		if (is_numeric($_GET["n"])){
			$mtime = microtime(); 
   			$mtime = explode(" ",$mtime); 
   			$mtime = $mtime[1] + $mtime[0]; 
   			$starttime = $mtime; 
			$factorial=($_GET["n"]*(($_GET["n"]+1)/2));
			$mtime = microtime(); 
   			$mtime = explode(" ",$mtime); 
   			$mtime = $mtime[1] + $mtime[0]; 
   			$endtime = $mtime; 
   			$totaltime = ($endtime - $starttime);  
			echo("The factorial of ".$_GET["n"]." is: ".$factorial." The answer was retrieved in: $totaltime seconds<br />");
			echo("<a href=\"./factorial.php\">Find another factorial</a>");
		}else{
			echo("non-numeric input detected");
		}
	}
	else if (isset($_GET["x"])){
		if (is_numeric($_GET["x"])){
			$factorial=0;
 			$mtime = microtime(); 
   			$mtime = explode(" ",$mtime); 
   			$mtime = $mtime[1] + $mtime[0]; 
   			$starttime = $mtime; 
			for ($i=1; $i<=$_GET["x"]; $i++){
				$factorial+=$i;
			}
			$mtime = microtime(); 
   			$mtime = explode(" ",$mtime); 
   			$mtime = $mtime[1] + $mtime[0]; 
   			$endtime = $mtime; 
   			$totaltime = ($endtime - $starttime); 
			echo("The factorial of ".$_GET["x"]." is: ".$factorial." This answer was retrieved in: $totaltime seconds<br />");
			echo("<a href=\"./factorial.php\">Find another factorial </a>");
		}else{
			echo("non-numeric input detected!");
		}
	}
	else{
?>
	Enter a number and the factorial of that number will be displayed
	<form action="#" method="GET">
	<input name="n" type="text" />
	<input type="submit" value="Go!" />
	</form>
	Enter a number here for a different method of getting the factorial of a number. This method should take a lot longer.<br />
	<strong>NOTE! For extremely large numbers, this may be incredibly slow!</strong>
	<form action="#" method="GET">
	<input name="x" type="text" />
	<input type="submit" value="Go!" />
	</form>
<?php
	}
?>
</body>
</html>