<html>
<head><title> Greatest and Smallest in 2d array</title>
</head>
<body>
<script language="javascript">
var i,j,greatest,smallest;
var num= new Array(2);
for(i=0;i<2;i++)
{
num[i]=new Array(3);
}
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
num[i][j]=parseInt(prompt("Enter the element",0));
}
}
greatest=num[0][0];
smallest=num[0][0];
document.write("Number you have entered are:<br>");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
document.write(num[i][j]+"<br>")
if(greatest<num[i][j])
{
greatest=num[i][j];
}
if(smallest>num[i][j])
{
smallest=num[i][j];
}
}
}
document.write("Greatest element is "+greatest);
document.write("<br>Smallest element is "+smallest);
</script>
</body>
</html>
<head><title> Greatest and Smallest in 2d array</title>
</head>
<body>
<script language="javascript">
var i,j,greatest,smallest;
var num= new Array(2);
for(i=0;i<2;i++)
{
num[i]=new Array(3);
}
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
num[i][j]=parseInt(prompt("Enter the element",0));
}
}
greatest=num[0][0];
smallest=num[0][0];
document.write("Number you have entered are:<br>");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
document.write(num[i][j]+"<br>")
if(greatest<num[i][j])
{
greatest=num[i][j];
}
if(smallest>num[i][j])
{
smallest=num[i][j];
}
}
}
document.write("Greatest element is "+greatest);
document.write("<br>Smallest element is "+smallest);
</script>
</body>
</html>
No comments:
Post a Comment