Skip to content

Instantly share code, notes, and snippets.

@sujaykundu777
Created July 13, 2017 04:29
Show Gist options
  • Save sujaykundu777/3a49a4c03724624f10f8deb6afe079a6 to your computer and use it in GitHub Desktop.
Save sujaykundu777/3a49a4c03724624f10f8deb6afe079a6 to your computer and use it in GitHub Desktop.
Linear Search Using Javascript
<html>
<head>
<title> Linear Search </title>
<script type="text/javascript">
function linear_search(){
var found=0;
var size= parseInt(prompt("Enter the size of an array"));
var a = new Array(size);
for (var i=0; i<a.length; i++){
a[i] = parseInt(prompt("Enter Array Elements"));
}
var input = parseInt(prompt("Enter the Key Element to Search :"));
for(var i=0;i<a.length;i++){
if(input == a[i]){
found=1;
break;
}
}
if(found==1){
document.writeln("Element Found at " + a[i] + "Found at Position :" + i);
}
else {
document.writeln("Element Not Found !");
}
}
</script>
</head>
<body onload="linear_search()"> </body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment