CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
for( int i=0 ; i<1000; i++)
{
int L = -1, R = 10, M;
double[] MA = { 2.5, 3, 5.5, 7.5, 9.5, 11.5, 13.5, 15.5, 16, 17
};
double N;
Console.WriteLine("ENTER THE NUMBER:");
N =
Convert.ToDouble(Console.ReadLine());
while (L + 1 != R)
{
M = (L + R) / 2;
if (MA[M] <= N)
{
L = M;
}
else
{
R = M;
}
}
if ((L >= 0) && (MA[L] == N))
{
Console.WriteLine(" {0} EXIST AT {1} INDEX NUMBER.", N, L + 1);
}
else
{
Console.WriteLine(" {0} DOES NOT EXIST.", N);
}
}
}
}
}
No comments:
Post a Comment