Hiển thị các bài đăng có nhãn Thiết kế Website. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Thiết kế Website. Hiển thị tất cả bài đăng

Thứ Sáu, 8 tháng 11, 2013

JavaScript: Kiểm tra số n (nguyên, nhập từ bàn phím) có phải số nguyên tố không ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<script>
var i,n,nt=1;
function nguyento(x){
if(x==1 || x==2) nt=1;
if(x>2){
for(i=2;i<=Math.sqrt(x);i++){
if(x%i==0){nt=0; break;}
}
}
return nt;
}
n=prompt("Nhap gia tri n:");
if(nguyento(n)==1) document.write(n + " LA so nguyen to")
else document.write(n + " KHONG la so nguyen to")
</script>
</body>
</html>

Thứ Hai, 4 tháng 11, 2013

JavaScript: Tìm UCLN, BCNN của 2 số a, b (nguyên, nhập từ bàn phím)

<html>
<head>
<title>UCLN</title>
</head>
<body>
<script language="JavaScript">
var a,b;
function UCLN(x,y){
while(x!=y)   {
            if(x>y) x=x-y;
            else y=y-x;
}
return x;
}
a=prompt("Nhap gia tri a:");
b=prompt("Nhap gia tri b:");
document.write("Uoc chung lon nhat: " + UCLN(a,b))
document.write("Boi chung nho nhat: " + a*b/UCLN(a,b))
</script>
</body>
</html>
Tags: Lập trình, JavaScript, BCNN, UCLN

Thứ Hai, 14 tháng 10, 2013

JavaScript: Giải phương trình bậc hai Ax2 + Bx + C = 0


<html>
<head>
<title>Giai phuong trinh bac 2</title>
<script language="JavaScript">
function giai(form){
var x1,x2;
var x,y,z,delta;
x= parseInt(form.a.value);
y= parseInt(form.b.value);
z= parseInt(form.c.value);
delta=(y*y-4*x*z)
if(delta ==0){
alert("phuong trinh co nghiem kep");
x1=-y/(2*x) ;
x2=-y/(2*x);
form.x.value=eval(x1);
form.y.value=eval(x2);
}
else if(delta<0){
alert("phuong trinh vo nghiem");

else{
alert("phuong trinh co hai nghiem");
x1=(-y-Math.sqrt(delta))/(2*x);
x2=(-y+Math.sqrt(delta))/(2*x);
form.x.value=eval(x1);
form.y.value=eval(x2);
}
}
</script>
</head>
<body>
<form method="post">
<center>
<br>Nhap gia tri a:
<input type="text" name="a" value="">
<br> Nhap gia tri b:
<input type="text" name="b" value="">
<br>Nhap gia tri c:
<input type="text" name="c" value="">
<br>Đáp số:
<input type="text" name="x" value="">
<input type="text" name="y" value="">
<input type="button" value="giai" onClick="giai(this.form)">
</center>
</form>
</body>
</html>
[Download Mã nguồn: Chờ 5s, sau đó nhấn SKIP AD (để bỏ qua Quảng cáo)]

JavaScript: Giải phương trình bậc nhất Ax + B = 0


<html>
<head>
<title>giai phuong trinh bac 1</title>
<script language="JavaScript">
function giai(form){
var x;
var a,b;
a= parseInt(form.a.value);
b= parseInt(form.b.value);

if(a==0){
if(b==0) alert("phuong trinh vo so nghiem");
else alert("phuong trinh vo nghiem");
}
else{ 
alert("phuong trinh co 1 nghiem");
x=-b/a;
form.x.value=eval(x);
}
}
</script>
</head>
<body>
<form method="post">
<center>
<br>Nhap gia tri a:
<input type="text" name="a" value="">
<br> Nhap gia tri b:
<input type="text" name="b" value="">

<br>Đáp số:
<input type="text" name="x" value="">
<input type="button" value="giai" onClick="giai(this.form)">
</center>
</form>
</body>
</html>
[CLICK Download Mã nguồn: Chờ 5s, sau đó nhấn SKIP AD (để bỏ qua Quảng cáo)]

JavaScript: Code tạo chương trình máy tính điện tử


<html>
<head><script LANGUAGE="JavaScript">
function a_plus_b(form) {
            a=eval(form.a.value)
            b=eval(form.b.value)
            c=a+b
            form.ans.value = c
}
function a_minus_b(form) {
            a=eval(form.a.value)
            b=eval(form.b.value)
            c=a-b
            form.ans.value=c
}
function a_times_b(form) {
            a=eval(form.a.value)
            b=eval(form.b.value)
            c=a*b
            form.ans.value=c
}
function a_div_b(form) {
            a=eval(form.a.value)
            b=eval(form.b.value)
            c=a/b
            form.ans.value = c
}
function a_pow_b(form) {
            a=eval(form.a.value)
            b=eval(form.b.value)
            c=Math.pow(a, b)
            form.ans.value = c
}
</script>
<title>May tinh don gian</title>
</head>
<body>
<form name="formx">
<p><input type="text" size="4" value="12" name="a">
<input type="button" value="  + " onClick="a_plus_b(this.form)">
<input type="button" value="  -  " onClick="a_minus_b(this.form)">
<input type="button" value="  x  " onClick="a_times_b(this.form)">
<input type="button" value="/  " onClick="a_div_b(this.form)">
<input type="button" value="  ^  " onClick="a_pow_b(this.form)">
<input type="number" size="4" value="3" name="b"> =
<input type "number" value="0" name="ans" size="9"> </p>
</form>
</body>
</html>
Tags: Lập trình, JavaScript, máy tính điện tử

Bài đăng phổ biến