Docsity

Notes sur la correction du Web Dynamique, Notes de Informations et informatique

Toggle sidebar
bg1
TD1 Web Dynamique Mohamed Belhassen
1
Correction TD 2
Exercice 1 : Random/While
<?php
$a;
$b;
$c;
do{
$a=rand();
$b=rand();
$c=rand();
}while($a%2!=0 || $b%2==0 || $c%2!=0 );
echo " a=$a , b=$b , c=$c";
?>
Exercice 2 : Random/While
Solution avec la boucle while :
<?php
$a=4;
$tirage;
$compteur=0;
do{
$tirage=rand(0,1000);
$compteur++;
}while($tirage!=$a );
echo " le nombre de tirages pour obtenir le nombre $a est :$compteur";
?>
Solution avec la boucle for :
<?php
$a=4;
$tirage=rand(0,1000);
for ($compteur=1; $tirage!=$a ; $compteur++ )
{
$tirage=rand(0,1000);
}
echo " le nombre de tirages pour obtenir le nombre $a est :$compteur";
?>
Exercice 3 : for/foreach
<?php
echo "solution 1 <br/>";
$t=array(1=>1,
2=>2,
3=>3,
4=>4,
5=>5,
6=>6,
7=>7,
8=>8,
docsity.com
pf2

Aperçu partiel du texte

Télécharge Notes sur la correction du Web Dynamique et plus Notes au format PDF de Informations et informatique sur Docsity uniquement!

TD1 Web Dynamique Mohamed Belhassen 1

Correction TD 2

Exercice 1 : Random/While

**Exercice 2** : Random/While _Solution avec la boucle while :_ _Solution avec la boucle for :_ **Exercice 3** : for/foreach "; $t=array(1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8,

docsity.com

TD1 Web Dynamique Mohamed Belhassen 2

10=>a, 11=>b, 12=>c, 13=>d, 14=>e, 15=>f); for ($compteur=1; $compteur<16 ; $compteur++ ) { echo "indice: $compteur, indice to hex : ".dechex($compteur). " , t[$compteur]= $t[$compteur]
"; } echo "solution 2
"; foreach ($t as $key=>$val ) { echo "indice: $key, indice to hex : ".dechex($key). " , t[$key]= $val
"; } ?> Exercice 4 : PGCD

docsity.com