Javascript - Tìm số lớn nhất trong năm số

Tìm số lớn nhất trong năm số

Dùng câu lệnh có điều kiện để tìm số lớn nhất trong năm số. Dùng Alert để hiển thị kết quả.

Nhập: -5, -2, -6, 0, -1
Kết quả: 0

Ví dụ:

JavaScript: Find the largest of five numbers

Mã nguồn:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Write a JavaScript conditional statement to find the largest of five numbers</title>
<script>
a=-5;
b=-2;
c=-6;
d= 0;
f=-1;
if (a>b && a>c && a>d && a>f)
{
    document.write(a);
}
else if (b>a && b>c && b>d && b>f)
{
    document.write(b);
}
else if (c>a && c>b && c>d && c>f)
{
    document.write(c);
}
else if (d>a && d>c && d>b && d>f)
{
    cdocument.write(d);
}
else
{
    document.write(f);
}
</script>
</head>
<body>
  
</body>
</html>

hiepsiithml1

Lưu đồ thuật toán:

Flowchart: JavaScript:- Find the largest of five numbers



Tư vấn lộ trình CNTT 🤖