<html>
<head>
<title>linear</title>
<script type="text/javascript">
             <!--
             function linear()
{
    var n=parseInt(prompt("Enter the size of an array"));
    var a=new Array(n);
    var t=0;
    for(var i=0; i<a.length; i++)
    {
        a[i]=parseInt(prompt("Enter array elements"));
    }
    var k=parseInt(prompt("Enter the key element to search: "));
    for(var i=0; i<a.length; i++)
    {
        if(k==a[i])
        {
            t=1;
            break;
        }
    }
    if(t==1)
    {
        document.writeln("Element "+a[i]+ " Found at Position:"+i);
    }
    else
    {
        document.writeln("Element Not Found");
    }
}
</script>
</head>
<body  onLoad="linear()"></body>
</html>

 

 

OUTPUT:

linearsearch programming9

We will provide you Codes for C, C++, Java, Python, Web Technologies and many more

C Codes FlowCharts C++ Codes Java Codes HTML Tech Videos

Submit Your Code to Share with other Friends

Signup to programming9.com

Register Here Login Here