<html>
<head>
	<title>Binary Search</title>
	<script type="text/javascript">
	function binary()
	{
		var n=parseInt(prompt("enter the size of an array: "));
		var a=new Array(n);
		var p=0;
		for(var i=0;i<a.length;i++)
		{
			a[i]=parseInt(prompt("enter array elements"));
		}
		for(var i=0;i<a.length;i++)
		{
			for(var j=i+1;j<a.length;j++)
			{
			if(a[i]>a[j])
				{
				var t=a[i];
				a[i]=a[j];
				a[j]=t;
				}
			}
		}
		var k=parseInt(prompt("enter the key element "));
                var i=0;
		var u=parseInt(a.length-1);
		while(i<=u)
		{
			var m=parseInt((i+u)/2);
			if(k==a[m])
			{
				p=1;
				break;
			}
			else if(k>a[m])
			{
			i=m+1;
			}
			else if(k<a[m])
			{
			 u=m-1;
			}
		}
	if(p==1)
		document.writeln("element found at :"+m);
	else
		document.writeln("element not found");

	}
</script>
</head>
<body onLoad="binary();"></body>
</html>

 

 OUTPUT:

 

binsearch programming9

FlowCharts

You can access the complete Algorithm and Program for the Arithmetic operations in c.
C Program to Find Roots of a Quadratic Equation and Java Program to Find Roots of a Quadratic Equation. Right Click...
Raptor Flow Chart to Print All the Numbers up to a Given Number. RAPTOR is a flowchart-based programming environment, designed...
We already written a program for the two's complement using C-Programming. This program is a combination of many user defined...
Raptor Flow Chart to Find Biggest of Two Numbers. RAPTOR is a flowchart-based programming environment, designed to help students to...

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