JavaScript: Tìm UCLN, BCNN của 2 số a, b (nguyên, nhập từ bàn phím)

Người đăng: share-nhungdieuhay on Thứ Hai, 4 tháng 11, 2013

<html>
<head>
<title>UCLN</title>
</head>
<body>
<script language="JavaScript">
var a,b;
function UCLN(x,y){
while(x!=y)   {
            if(x>y) x=x-y;
            else y=y-x;
}
return x;
}
a=prompt("Nhap gia tri a:");
b=prompt("Nhap gia tri b:");
document.write("Uoc chung lon nhat: " + UCLN(a,b))
document.write("Boi chung nho nhat: " + a*b/UCLN(a,b))
</script>
</body>
</html>
Tags: Lập trình, JavaScript, BCNN, UCLN

{ 0 nhận xét... read them below or add one }

Đăng nhận xét