sort.html
<html>
<body>
<script language="Javascript">
var i,j,n;
n=parseInt(prompt("Enter the array size","3"));
var a= new Array();
for(i=1;i<=n;i++){
a[i]=parseInt(prompt("enter the element for array","0"));
}
document.writeln("Given Elements are"+"<br>");
for(i=1;i<=n;i++){
document.writeln(a[i]);
}
for (i=1;i<=n;i++){
for(j=i+1;j<=n;j++){
if (a[i]>a[j]){
var t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
document.write("<br>");
document.writeln("sorted Elements in ascending order are"+"<br>");
for(i=1;i<=n;i++){
document.writeln(a[i]);
}
document.write("<br>");
document.writeln("sorted Elements in descending order are"+"<br>");
for(i=n;i>=1;i--){
document.writeln(a[i]);
}
</script></body></html>
OUTPUT:
No comments:
Post a Comment