<?php
function casalExponencial($i) {
if ($i==1) {
return 1;
}
if ($i==2) {
return 1;
}
return casalExponencial($i - 1) + casalExponencial($i - 2);
}
$entrada = (int) trim(fgets(STDIN));
echo casalExponencial($entrada);
?>
<?php
$quantidadeDeLivros = (int) trim(fgets(STDIN));
$maisPaginasTitulo = "";
$maisPaginas_P = 0;
for ($i=0 ; $i<$quantidadeDeLivros ; $i++) {
$titulo = trim(fgets(STDIN));
$ano = (int) fgets(STDIN);
$paginas = (int) fgets(STDIN);
if ($paginas > $maisPaginas_P) {
$maisPaginas_P = $paginas;
$maisPaginasTitulo = $titulo;
}
}
echo "Livro com mais paginas: $maisPaginasTitulo ($maisPaginas_P paginas)";
?>
<?php
$indiceMaximoArray = (int) trim(fgets(STDIN));
$arrayMoedas = [];
$umCentavo = 0;
$cincoCentavos = 0;
$dezCentavos = 0;
$vinteECincoCentavos = 0;
$cinquentaCentavos = 0;
$umReal = 0;
for ($i=0 ; $i<$indiceMaximoArray ; $i++) {
$arrayMoedas[$i] = (int) trim(fgets(STDIN));
if ($arrayMoedas[$i] == 1) {
$umCentavo++;
} elseif ($arrayMoedas[$i] == 5) {
$cincoCentavos++;
} elseif ($arrayMoedas [$i] == 10) {
$dezCentavos++;
} elseif ($arrayMoedas [$i] == 25) {
$vinteECincoCentavos++;
} elseif ($arrayMoedas[$i] == 50) {
$cinquentaCentavos++;
} else {
$umReal++;
}
}
echo "Moedas de 1 centavo: $umCentavo\n";
echo "Moedas de 5 centavos: $cincoCentavos\n";
echo "Moedas de 10 centavos: $dezCentavos\n";
echo "Moedas de 25 centavos: $vinteECincoCentavos\n";
echo "Moedas de 50 centavos: $cinquentaCentavos\n";
echo "Moedas de 1 real: $umReal\n";
?>
<?php
$vetorEntrada = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
function inverterOrdem($vetor){
for ($x= 9; $x >= 0 ;$x--) {
echo "$vetor[$x]\n";
}
}
inverterOrdem($vetorEntrada);
?>
<?php
function fatorial($num) {
if ($num == 0) {
return 1;
} else {
return $num * fatorial($num -1);
}
}
echo "Digite um numero qeu voce deseja saber o fatorial: ";
$n = intval(trim(fgets(STDIN)));
if ($n >= 0) {
$resultado = fatorial($n);
echo "\nO fatorial do numero $n eh $resultado\n";
} else {
echo "\nNao existe fatorial de numeros negativos!\n";
}
?>
To embed this project on your website, copy the following code and paste it into your website's HTML: