Skip to content

Commit

Permalink
novos exercicios.
Browse files Browse the repository at this point in the history
  • Loading branch information
neves committed Feb 18, 2010
1 parent b7018a4 commit 04cb480
Show file tree
Hide file tree
Showing 57 changed files with 1,472 additions and 5 deletions.
41 changes: 41 additions & 0 deletions algoritmos/php/00-sintaxe/if.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?
$um = 1;
$dois = 2;
// if simples
if ($dois > $um)
echo "O maior eh o $dois \n";

// if com mais de um comando precisa de escopo.(dois pontos + endif)
if ($dois > $um):
echo "O maior eh o $dois \n";
echo "e o menor eh o $um \n";
endif;

// if e else
if ($um > $dois)
echo "O maior eh o $um \n";
else
echo "O maior eh o $dois \n";

// if e else com escopo
if ($um > $dois):
echo "O maior eh o $um \n";
echo "e o menor eh o $dois \n";
else:
echo "O maior eh o $dois \n";
echo "e o menor eh o $um \n";
endif;

// if dentro de else
if ($um > $dois)
echo "O maior eh o $um \n";
else
if ($um == $dois)
echo "Os numeros sao iguais! \n";

// elseif
if ($um > $dois)
echo "O maior eh o $um \n";
elseif ($um == $dois)
echo "Os numeros sao iguais! \n";
?>
19 changes: 19 additions & 0 deletions algoritmos/php/01-variaveis/01-soma.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?

// ENTRADA

$n1 = $argv[1];
$n2 = $argv[2];

// LOGICA

$soma = $n1 + $n2;

// SAIDA

echo "
$n1 + $n2 = $soma
"

?>
25 changes: 25 additions & 0 deletions algoritmos/php/01-variaveis/02-relatorio.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?

// ENTRADA

$nome = "John Doe";
$email = "[email protected]";
$idade = 64;
$estado = "PR";
$cidade = "Maringa";
$sexo = "Masculino";

// SAIDA

echo "
____________________Dados Cadastrais____________________
Nome : $nome
Email: $email
Idade: $idade anos
Local: $cidade/$estado
Sexo : $sexo
========================================================
";

?>
40 changes: 40 additions & 0 deletions algoritmos/php/01-variaveis/04-tabuada.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?

// ENTRADA

$n = $argv[1];

// LOGICA

$n1 = $n * 1;
$n2 = $n * 2;
$n3 = $n * 3;
$n4 = $n * 4;
$n5 = $n * 5;
$n6 = $n * 6;
$n7 = $n * 7;
$n8 = $n * 8;
$n9 = $n * 9;
$n10 = $n * 10;

// SAIDA

echo "
-------------
TABUADA DO $n
=============
$n x 1 = $n1
$n x 2 = $n2
$n x 3 = $n3
$n x 4 = $n4
$n x 5 = $n5
$n x 6 = $n6
$n x 7 = $n7
$n x 8 = $n8
$n x 9 = $n9
$n x 10 = $n10
_____________
"

?>
28 changes: 28 additions & 0 deletions algoritmos/php/01-variaveis/05-bimestre.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?

// ENTRADA

$b1 = $argv[1];
$b2 = $argv[2];
$b3 = $argv[3];
$b4 = $argv[4];

// LOGICA

$media = ($b1 + $b2 + $b3 + $b4) / 4;

// SAIDA

echo "
Notas dos Bimestres
===================
1 Bimestre: $b1
2 Bimestre: $b2
3 Bimestre: $b3
4 Bimestre: $b4
-------------------
Media Anual: $media
";

?>
25 changes: 25 additions & 0 deletions algoritmos/php/01-variaveis/06-operacoes_basicas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?

// ENTRADA

$n1 = $argv[1];
$n2 = $argv[2];

// LOGICA

$soma = $n1 + $n2;
$sub = $n1 - $n2;
$mult = $n1 * $n2;
$div = $n1 / $n2;

// SAIDA

echo "
$n1 + $n2 = $soma
$n1 - $n2 = $sub
$n1 x $n2 = $mult
$n1 / $n2 = $div
";

?>
18 changes: 18 additions & 0 deletions algoritmos/php/01-variaveis/07-char2codigo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?

// ENTRADA

$char = $argv[1];

// LOGICA

$codigo = ord($char);

// SAIDA

echo "
$char = $codigo
"

?>
18 changes: 18 additions & 0 deletions algoritmos/php/01-variaveis/08-codigo2char.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?

// ENTRADA

$codigo = $argv[1];

// LOGICA

$char = chr($codigo);

// SAIDA

echo "
$codigo = [$char]
"

?>
19 changes: 19 additions & 0 deletions algoritmos/php/01-variaveis/09-sorteio.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?

// ENTRADA

$min = $argv[1];
$max = $argv[2];

// LOGICA

$sorteio = mt_rand($min, $max);

// SAIDA

echo "
sorteado o numero $sorteio entre $min e $max.
";

?>
19 changes: 19 additions & 0 deletions algoritmos/php/01-variaveis/10-resultados_por_paginas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?

// ENTRADA

$resultados = $argv[1];
$porPagina = $argv[2];

// LOGICA

$paginas = ceil($resultados / $porPagina);

// .............................. SAÍDA ..............................

echo "
$resultados resultados exibidos em $paginas paginas
";

?>
21 changes: 21 additions & 0 deletions algoritmos/php/01-variaveis/13-resto_da_divisao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?

// ENTRADA

$n1 = $argv[1];
$n2 = $argv[2];

// LOGICA

$divisao = floor($n1 / $n2);
$resto = $n1 % $n2;

// SAIDA

echo "
$n1 dividido por $n2 = $divisao com resto $resto
$n2 x $divisao + $resto = $n1
"

?>
21 changes: 21 additions & 0 deletions algoritmos/php/01-variaveis/14-resto_da_divisao_manual.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?

// ENTRADA

$n1 = $argv[1];
$n2 = $argv[2];

// LOGICA

$divisao = floor($n1 / $n2);
$resto = $n1 - $divisao * $n2;

// SAIDA

echo "
$n1 dividido por $n2 = $divisao com resto $resto
$n2 x $divisao + $resto = $n1
"

?>
21 changes: 21 additions & 0 deletions algoritmos/php/01-variaveis/15-area_e_perimetro_do_quadrado.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?

// ENTRADA

$lado = $argv[1];

// LOGICA

$area = $lado * $lado;
$perimetro = 4 * $lado;

// SAIDA

echo "
O quadrado de lado {$lado}cm,
possui area de {$area}cm2 quadrados e
perimetro de {$perimetro}cm.
";

?>
22 changes: 22 additions & 0 deletions algoritmos/php/01-variaveis/18-troca2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?

// ENTRADA

$a = $argv[1];
$b = $argv[2];

// LOGICA

// utilizar uma variável temporária para fazer a troca
$temp = $a;
$a = $b;
$b = $temp;

// SAIDA

echo "
$a $b
"

?>
27 changes: 27 additions & 0 deletions algoritmos/php/01-variaveis/19-troca4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?

// ENTRADA

$a = $argv[1];
$b = $argv[2];
$c = $argv[3];
$d = $argv[4];

// Trocar a e d
$temp = $a;
$a = $d;
$d = $temp;

// Trocar b e c
$temp = $c;
$c = $b;
$b = $temp;

// SAIDA

echo "
$a $b $c $d
"

?>
Loading

0 comments on commit 04cb480

Please sign in to comment.