Page

Program to reverse array in java script

<html>
<head><center><h1>to reverse array</h1></center>
<title>date function</title>
<script type="text/javascript">
a=new Array(4);
alert("enter the elements of array");
for(i=0;i<a.length;i++)
{
a[i]=parseInt(prompt("enter value"," "));
}
alert("the array is");
for(i=0;i<a.length;i++)
{
document.write("<br>"+"a["+i+"] ="+a[i]);
}
b=new Array(4);
b=a.reverse();
document.write("the reversed array is ");
for(i=0;i<b.length;i++)
{
document.write("<br>"+"b["+i+"] ="+b[i]+"<br>");
}
</script>
</head>
</html>

Program to watch time at title bar in java script

<html>
<head><center><h1>watch time at title bar</h1></center>
<title>date function</title>
<script type="text/javascript">
function disp_time()
{
d=new Date();
hr=d.getHours();
mn=d.getMinutes();
sc=d.getSeconds();
document.write("date :"+d.getDate()+"<br>");
document.write("time :"+hr+":"+mn+":"+sc);
}
</script>
</head>
<body onclick="disp_time()">
</html>

Program for multiplication of two matrices in java script

<html>
<head><h2><center>program for multiplication of two matrices"</h2></center></head>
<body>
<script type="text/javascript">
function mul()
{
m=parseInt(prompt("enter the number of rows for ist matrix"," "))
n=parseInt(prompt("enter the number of columns for ist matrix"," "));
p=parseInt(prompt("enter the number of rows for 2nd matrix"," "));
q=parseInt(prompt("enter the number of columns for 2nd matrix"," "));

if(n==p)
{
alert("enter elements for first matrix");
a = new Array(m);
for(i=0;i<m;i++)
{
a[i]=new Array(n);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=parseInt(prompt("enter value"," "));
}}
b=new Array(p);
for(i=0;i<p;i++)
{
b[i]= new Array(q);
}
alert("enter elements for second matrix");
for(s=0;s<p;s++)
{
for(t=0;t<q;t++)
{
b[s][t]=parseInt(prompt("enter value"," "));
}}

c=new Array(m);
for(i=0;i<m;i++)
{
c[i]=new Array(q);
}


for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<p;k++)
{
c[i][j]=parseInt(c[i][j]+parseInt((a[i][k]*b[k][j])));
}}}
document.write("the multiplication  of  two matrices is =>"+"<br>");
for(i=0;i<m;i++)
{
document.write("<br>");
for(j=0;j<q;j++)
{
document.write(c[i][j]+"&nbsp&nbsp");
}}}
else
document.write("multiplication not possible");
}
</script>
<button onclick="mul()">multiply</button>
</body>
</html>

Program to add two matrices of order m x n in java script

<html>
<head><h2><center>program to add two matrices of order m x n</h2></center></head>
<body>
<script type="text/javascript">
function add()
{
m=parseInt(prompt("enter the number of rows"," "));
n=parseInt(prompt("enter the number of columns"," "));
alert("enter elements for first matrix");
a = new Array(m);
for(i=0;i<m;i++)
{
a[i]=new Array(n);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=parseInt(prompt("enter value"," "));
}}
b=new Array(m);
for(i=0;i<m;i++)
{
b[i]=new Array(n);
}
alert("enter elements for second matrix");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=parseInt(prompt("enter value"," "));
}}

c=new Array(m);
for(i=0;i<m;i++)
{
c[i]=new Array(n);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=parseInt(a[i][j]+b[i][j]);
}}
document.write("the addition of  two matrices is =>"+"<br>");
for(i=0;i<m;i++)
{
document.write("<br>");
for(j=0;j<n;j++)
{
document.write(c[i][j]+"&nbsp&nbsp");
}}
}
</script>
<button onclick="add()">sum</button>
</body>
</html>

Program to table of any number in java script

<html>
<head><h2><center>program to table of any number</h2></center></head>
<body>
<script type="text/javascript">
n=parseInt(prompt("enter the number of which we have to print the table"," "));
document.write("table of "+n+"  is  =>"+"<br>");
for(i=1;i<=10;i++)
{
m=n*i;
document.write(n+"*"+i+" =   "+m+"<br>");
}
</script>
</body>
</html>

Program to print the series in java script

<html>
<head><h2><center>program to print the series</h2></center></head>
<body>
<script type="text/javascript">
n=parseInt(prompt("enter the number of rows"," "));
for(i=1;i<=n;i++)
{
document.write("<br>");
for(j=1;j<=n-i;j++)
document.write("&nbsp&nbsp");
for(k=1;k<=i;k++)
document.write(k);
for(l=i-1;l>0;l--)
document.write(l);
}
</script>
</body>
</html>

Program to evaluate series 1+1/2+1/3+1/4+-------+1/N in java script

<html>
<head><h2><center>program to evaluate series 1+1/2+1/3+1/4+-------+1/N</h2></center></head>
<body>
<script type="text/javascript">
n=parseInt(prompt("enter the value for n"," "));
s=0.0;
for(i=1;i<=n;i++)
{
s=s+(1/i);
}
document.write("the sum of series is "+s);
</script>
</body>
</html>

Program to find the reverse of a number in java script

<html>
<head><h2><center>program to find the reverse of a number</h2></center></head>
<body>
<script type="text/javascript">
n=parseInt(prompt("enter the number"," "));
rev=0;
x=n;
while(n>0)
{
m=n%10;
rev=parseInt(rev*10+m);
n=parseInt(n/10);
}
document.write("reverse of a given number "+x+"  is "+rev);
</script>
</body>
</html>

Program to check wheather the given number is armstrong or not in java script

<html>
<head><h2><center>program to check wheather the given number is armstrong or not</h2></center></head>
<body>
<script type="text/javascript">
n=parseInt(prompt("enter the number"," "));
sum=0;
x=n;
while(n>0)
{
m=n%10;
l=m*m*m;
sum=parseInt(sum +l);
n=parseInt(n/10);
}
document.write(sum);
if(sum==x)
document.write("number "+x+"  is armstrong number");
else
document.write("number "+x+"is not an armstrong number");
</script>
</body>
</html>

Program to print the sum of digits of given number in java script

<html>
<head><h2><center>program to print the sum of digits of given number</h2></center></head>
<body>
<script type="text/javascript">
n=parseInt(prompt("enter the number"," "));
sum=0;
x=n;
while(n>0)
{
m=n%10;
n=n/10;
sum=parseInt(sum+m);
}

document.write("the sum of digits of "+"     "+x+"   "+"is   "+"     "+sum);
</script>
</body>
</html>