By GokiSoft.com| 19:32 23/10/2023|
Học JS

Giải phương trình bậc nhất bằng Javascript BT1605

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

Liên kết rút gọn:

https://gokisoft.com/1605

Bình luận

avatar
Lê Trọng Nghĩa [community,C2009I]
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>


avatar
Vũ Trung Kiên [C2009I]
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>


avatar
Triệu Văn Lăng [T2008A]
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>


avatar
hainguyen [T2008A]
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>


avatar
Trần Văn Lâm [T2008A]
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>


avatar
Trần Thị Khánh Huyền [T2008A]
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>


avatar
Nguyễn Xuân Mai [T2008A]
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>


avatar
Do Trung Duc [T2008A]
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>


avatar
Do Trung Duc [T2008A]
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>


avatar
Nguyễn Tiến Đạt [T2008A]
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>