INPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
int[] marks = { 11, 12, 14, 17, 19, 22, 29, 33, 36,39,40 };
int Left = -1, Right=8, mid,find;
foreach (int n in marks)
{
Console.Write("{0}\t", n);
}
Console.WriteLine("\n\nserch
the no");
find=Convert.ToInt32(Console.ReadLine());
while (Left + 1 != Right)
{
mid
= (Left + Right) / 2;
if (marks[mid] <= find)
{
Left
= mid;
}
else
{
Right = mid;
}
}
if (Left >= 0 && marks[Left] == find)
{
Console.WriteLine("index no : {0}",Left+
1);
}
else
{
Console.WriteLine("NOt
available");
}
}
}
}
No comments:
Post a Comment