By GokiSoft.com|
10:02 18/01/2021|
Học JS
Bài tập - Giải phương trình bậc nhất ax + b = 0
Tạo 1 website khi bắt đầu bật chương trình lên thì thực hiện các bước như sau
Giải phương trình bậc nhất (ax + b = 0)
Bước 1 : Hiển thị prompt để nhập giá trị cho a
Bước 2: Nhập giá tri cho b bằng prompt
Bước 3 : In kết quả 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)
![Nguyễn Anh Vũ [T2008A]](https://www.gravatar.com/avatar/8863d24ed74b396082becbc4db8331fd.jpg?s=80&d=mm&r=g)
Nguyễn Anh Vũ
2020-10-20 09:35:01
#pt bac nhat.html
<!DOCTYPE html>
<html>
<head>
<title>Bai Tập 2</title>
<meta charset="utf-8">
<style type="text/css">
.row{
width: 100%;
height: 20px;
background-color: #FFFF99;
color: black
}
.menu{
width:100%;
height:35px;
background-color: #CCFFFF;
padding-top: 10px;
left: 10px;
color: white
}
</style>
</head>
<body>
<div class="row">
Giải Phương Trình Bậc nhất ax+b=0
</div>
<div class="menu">
<button onclick="NhapA()" style="background-color: #CCFF66" > Nhập A</button>
<button onclick="NhapB()" style="background-color: #CCFF66"> Nhập B</button>
<button onclick="Ketqua()" style="background-color: #CCFF66"> Tổng ax + b =</button>
</div>
<script type="text/javascript">
var a,b;
function NhapA(){
a=parseInt(prompt('NhapA'))
}
function NhapB(){
b=parseInt(prompt('NhapB'))
}
function Ketqua(){
if (a == 0) {
if (b == 0) {
alert('ptvsn')
}else{
alert('ptvn')
}
}else{
x = -b/a
alert(x)
}
}
</script>
</body>
![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-18 10:29:18
#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>
![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-17 14:37:01
#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>
![vuong huu phu [T2008A]](https://www.gravatar.com/avatar/307a5cf29780afab49706dc8b15b86c6.jpg?s=80&d=mm&r=g)
vuong huu phu
2020-10-16 14:54:45
<!DOCTYPE html>
<html>
<head>
<title> bai2</title>
</head>
<body>
<meta charset="utf-8">
<script type="text/javascript">
var a =prompt(" nhập số a ");
var b =prompt(" nhập số b ");
if(a==0){document.write("pt vo nghiem")};
if(b==0){document.write("pt vo nghiem")};
var x;
if( a>0 && b>0){
x=(-b/a);
document.write(x);
}
</script>
</body>
</html>
![nguyễn Sử [T2008A]](https://www.gravatar.com/avatar/47487be2776ac2ec915b0936ef7ab5ae.jpg?s=80&d=mm&r=g)
nguyễn Sử
2020-10-16 12:09:11
#giaiphuongtrinh.html
<!DOCTYPE html>
<html>
<head>
<title>Giai phuong trinh bac nhat</title>
</head>
<body>
<script type="text/javascript">
var x;
var a = prompt('a');
var b = prompt('b');
if (a==0) {
if (b==0) {
alert ("ptvsn")
}else {
alert ("ptvn")
}
}else {
x = (-b/a);
alert(x)
}
</script>
</body>
</html>
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2020-10-16 10:15:25
#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>
![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-16 10:04:24
#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>
![Đức Sơn [T2008A]](https://www.gravatar.com/avatar/d2b971b7bc54e4a9689c3e2240f27949.jpg?s=80&d=mm&r=g)
Đức Sơn
2020-10-16 09:53:44
#js3.html
<!DOCTYPE html>
<html>
<head>
<title>JS</title>
</head>
<body>
<script type="text/javascript">
var a=prompt('Nhap gia tri a:')
var b=prompt('Nhap gia tri b:')
if (a==0) {
if (b==0) {
alert ("Phuong trinh vo so nghiem")
} else {
alert ("Phuong trinh vo nghiem")
}
} else {
x = -b/a
alert(x)
}
</script>
</body>
</html>
![Nguyễn Hữu Hiếu [T2008A]](https://www.gravatar.com/avatar/ca2884508b617fee77f000c7d99c219d.jpg?s=80&d=mm&r=g)
Nguyễn Hữu Hiếu
2020-10-16 08:52:54
#1605.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var a = prompt("Nhap a = ", 0);
var b = prompt("Nhap a = ", 0);
var x = -b/a;
if (a == 0) {
if (b == 0) {
document.write("PT vo so nghiem");
}
else {
document.write("PT vo nghiem");
}
}
else {
document.write(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-16 08:43:58
#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>