Desenvolvimento de Ambiente Web (FAZAG 2008.2): Correção da Prova II

From AdonaiMedrado.Pro.Br
Revision as of 13:16, 8 December 2008 by Adonaimedrado (Talk | contribs) (New page: == Questão única == === Resposta em PHP === <code lang="html"> <html> <head> <title>Prova</title> </head> <body> <form action="index.php" method="POST"> <input type="text" name=...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Questão única

Resposta em PHP

<html>
	<head>
		<title>Prova</title>	
	</head>
<body>
 
	<form action="index.php" method="POST">
		<input type="text" name="txtEntrada" value="<?php if (count($_POST) != 0) echo $_POST["txtEntrada"]; ?>"/>
		<input type="submit" name="btExecutar" value="Executar Cálculo" />
		<input type="text" name="txtSaida" value="<?php if (count($_POST) != 0) echo CalcularResto(); ?>"/>
		<?php if (count($_POST) != 0) echo "Fatorial: ".CalcularFatorial(); ?>
	</form>	
	<?php
		function ConverterParaInteiro($str)
		{
			switch($str)
			{
				case "um": return 1;
				case "dois": return 2;
				case "três": return 3;
				case "quatro": return 4;
				case "cinco": return 5;
				case "seis": return 6;
				case "sete": return 7;
				case "oito": return 8;
				case "nove": return 9;
				case "dez": return 10;
			}	
		}
		function Fatorial($num)
		{
			if ($num!=1)
				return $num * Fatorial($num-1);
			else
				return 1;
		}
		function CalcularFatorial()
		{
			return Fatorial(ConverterParaInteiro(strtolower($_POST["txtEntrada"])));
		}
		function CalcularResto()
		{
			return CalcularFatorial()%21;			
		}
	?>
</body>
</html>