By GokiSoft.com|
19:32 23/10/2023|
Học JS
Giải phương trình bậc nhất bằng Javascript
Cho phương trình bậc nhất như sau
a*x + b= 0
Với a, b là số nguyên => tạo ngẫu nhiên
Hiển thị kết quả của x ra màn hình
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Lê Trọng Nghĩa [community,C2009I]](https://www.gravatar.com/avatar/1093e836f419101dc96b7e3f6aab4a56.jpg?s=80&d=mm&r=g)
Lê Trọng Nghĩa
2020-12-16 02:50:24
<!DOCTYPE html>
<html>
<head>
<title>Giải Phương Trình Bậc 1</title>
<meta charset="utf-8">
</head>
<body>
<script type="text/javascript">
var a = prompt('Nhập giá trị của a' +'<br>')
var b = prompt('Nhập giá trị của b')
c = -b / a
document.write('c =' +c)
</script>
</body>
</html>
![Vũ Trung Kiên [C2009I]](https://www.gravatar.com/avatar/abf994de48c0204239812f8d9a7dcf8c.jpg?s=80&d=mm&r=g)
Vũ Trung Kiên
2020-12-15 09:34:13
#PTBac1.html
<!DOCTYPE html>
<html>
<head>
<title>Phương Trình Bậc Nhất</title>
<meta charset="utf-8">
</head>
<body>
<script type="text/javascript">
a = prompt('Nhập a:')
b = prompt('Nhập b:')
kq = (-b) / a
document.write('x = ' +kq)
</script>
</body>
</html>
![Triệu Văn Lăng [T2008A]](https://www.gravatar.com/avatar/1348e3562c6492c26f796cb1f45982a1.jpg?s=80&d=mm&r=g)
Triệu Văn Lăng
2020-10-17 08:43:40
#ptbac1(2004).html
<!DOCTYPE html>
<html>
<head>
<title>Giai pt bac nhat</title>
</head>
<body>
<script type="text/javascript">
var a, b;
a=prompt("nhap a");
b=prompt("nhap b");
var x=(-b/a);
document.write("x= "+x);
</script>
</body>
</html>
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2020-10-16 13:49:31
#java1.html
<!DOCTYPE html>
<html>
<head>
<title>Bot</title>
</head>
<body>
<script type="text/javascript">
var a,b, x
a = prompt('Nhap a')
b = prompt('Nhap b')
function giai(a,b){
if(a==0) {
if (b==0) {
document.write('PTVSN')
str =+'PTVSN'
} else {
str =+ 'PTVN'
}
} else {
x = -b/a;
document.write('x = ' + x)
x = eval(x);
}
}
giai(a, b)
</script>
</body>
</html>
![Trần Văn Lâm [T2008A]](https://www.gravatar.com/avatar/cfc15c8cb7781ad669b013e01f9f1a6b.jpg?s=80&d=mm&r=g)
Trần Văn Lâm
2020-10-16 09:44:32
#b1.html
<!DOCTYPE html>
<html>
<head>
<title>Giai Phuong Trinh</title>
<meta charset="utf-8">
</head>
<body>
<div>
<div>
Giai phuong trinh bac nhat ax+b=0
</div>
<div>
<button onclick="nhapa()">Nhap a</button>
<button onclick="nhapb()">Nhap b</button>
<button onclick="printresult()">ke qua</button>
</div>
</div>
<script type="text/javascript">
var a,b;
function nhapa(){
a = prompt('Nhap a')
}
function nhapb(){
b = prompt('Nhap b')
}
function printresult(){
if (a == 0) {
if (b == 0) {
alert('ptvsn')
}else{
alert('ptvn')
}
}else{
x = -b/a
alert(x)
}
}
</script>
</body>
</html>
![Trần Thị Khánh Huyền [T2008A]](https://www.gravatar.com/avatar/554e115833778e4294a01aebe228f3d6.jpg?s=80&d=mm&r=g)
Trần Thị Khánh Huyền
2020-10-16 00:29:49
#giaiPTbac1.html
<!DOCTYPE html>
<html>
<head>
<title>giaiPTbac1</title>
<meta charset="utf-8">
</head>
<body>
<script type="text/javascript">
var a = prompt("Nhap a =");
var b = prompt("\nNhap b =");
if (a==0){
if(b==0){document.write("PTVSN");}
else {document.write("PTVN");}
}else{
var x = -b/a;
document.write("Phuong trinh co nghiem la ",x);
}
</script>
</body>
</html>
![Nguyễn Xuân Mai [T2008A]](https://www.gravatar.com/avatar/d3d863d6f47708501814fb41e9c38f31.jpg?s=80&d=mm&r=g)
Nguyễn Xuân Mai
2020-10-15 14:41:05
<!DOCTYPE html>
<html>
<head>
<title>ptbac1</title>
</head>
<body>
<script type="text/javascript">
a = prompt("Nhap gia tri cua a")
b = prompt("Nhap gia tri cua b")
document.write('a = ' + a + '</br>')
document.write('b = ' + b + '</br>')
if (a==0){
if (b==0){
document.write("\npt vo so nghiem");
} else {
document.write("\npt vo nghiem");
}
}else{
document.write("\nNghiem x =" + -b/a);
}
</script>
</body>
</html>
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2020-10-15 13:20:34
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
// GIAI PT ax + b = 0
var a,b,x
a = prompt('Nhap a')
b = prompt('Nhap b')
if (a==0) {
if (b==0) {
alert('Phuong trinh vo so nghiem')
}else{
alert('Phuong trinh vo nghiem')
}
} else{
x = -b/a
alert('phuong trinh co 1 nghiem la' +x )
}
</script>
</body>
</html>
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2020-10-15 12:00:20
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
// GIAI PT ax + b = 0
var a,b,x
a = prompt('Nhap a')
b = prompt('Nhap b')
if (a==0) {
if (b==0) {
alert('Phuong trinh vo so nghiem')
}else{
alert('Phuong trinh vo nghiem')
}
} else{
x = -b/a
alert('phuong trinh co 1 nghiem la' +x )
}
</script>
</body>
</html>
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2020-10-14 15:11:44
#phuongtrinhbac1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Giải phương trình bậc 1</title>
</head>
<body style="font-size: 30px;">
<script>
alert('Bài toán giải phương trình bậc nhất!!!');
a=prompt('Nhập a:');
b=prompt('Nhập b:');
if(a==0){
if(b==0){
document.write('Phương trình vô số nghiệm!!!')
}
else{
document.write('Phương trình vô nghiệm!!!')
}
}
else{
x=-b/a
document.write('Phương trình có nghiệm là '+x)
}
</script>
</body>
</html>