Javascript - Tìm số lớn nhất trong 2 số
Tìm số lớn nhất trong 2 số
Ví dụ:
Mã nguồn:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Write a JavaScript program that accept two integers and display the larger</title>
<script>
var num1, num2;
num1 = window.prompt("Input the First integer", "0");
num2 = window.prompt("Input the second integer", "0");
if(parseInt(num1, 10) > parseInt(num2, 10))
{
document.write("The larger of "+ num1+ " and "+ num2+ " is "+ num1+ ".");
}
else
if(parseInt(num2, 10) > parseInt(num1, 10))
{
document.write("The larger of "+ num1+" and "+ num2+ " is "+ num2+ ".");
}
else
{
document.write("The values "+ num1+ " and "+num2+ " are equal.");
}
</script>
</head>
<body>
</body>
</html>
Lưu đồ thuật toán: