

function estentier(s){
u=false;
if (!(isNaN(s))){
	if ((s>0) && (s=Math.floor(s))){
	u=true;
	}
}
return u;
}



function pgcd()
{
chaine=" <b><u>Algorithme d'Euclide</u></b><br/><br/> "
var a=document.getElementById('t1').value;
var b=document.getElementById('t2').value;
if ((estentier(a)) && (estentier(b))){
	a=eval(a);
	b=eval(b);
	gcd=b;
	c=Math.floor(a/b);
	d=a%b;
	if (b%d==0) {
	var gcd=d	;
	chaine=chaine + a+"  = "+b+" x " + c + " + " + "<font color=red>"+d+"</font><br/>";
		}
		else
		{
	chaine=chaine + a+"  = "+b+" x " + c + " + " + d +"<br/>";
	}
	a=b;
	b=d;
	document.getElementById('pgcdresult').innerHTML=chaine;
	
while (!(d==0))
{   c=Math.floor(a/b);
    	d=a%b;
    if (b%d==0) {
	var gcd=d	;chaine=chaine + a+"  = "+b+" x " + c + " + " + "<font color=red>"+d+"</font><br/>";
		}
		else
		{
	chaine=chaine + a+"  = "+b+" x " + c + " + " + d +"<br/>";
	}
	a=b;
	b=d;
	}
	chaine=chaine+"<br/> Le pgcd est <b>"+ gcd +"</b>" ;
	if (gcd==1) {chaine=chaine + "<br/><br/> (Les nombres "+document.getElementById('t1').value+" et " + document.getElementById('t2').value;
	chaine=chaine+ " sont premiers entre eux)";}
	document.getElementById('pgcdresult').innerHTML=chaine;
	}
	else
{
alert("Entrez des entiers strictement positifs!!!","pgcd");
}
}

