Presentasi 2

Tanggal 08 November 2012


using System;

namespace index_data
{
class Program
{
public static void Main(string[] args)
{
string ulang;
do
{
Console.Clear();
Console.ForegroundColor=ConsoleColor.Green;
Console.WriteLine("Index_Data");
//Deklarasi aray
int [] arrIndex = { 1, 2, 4, 5, 6, 7, 8, 9};
string [] data = { "12", "45", "15", "54", "75", "70", "80", "34", "55", "100"};

//Deklarasi variable
int high = arrIndex.Length-1;
int low = 0;
int cari;
int posisi;
bool ketemu;
ketemu = false;

//input
Console.Write("masukkan index yang di cari = ");
cari = Convert.ToInt32(Console.ReadLine());

if ( cari > arrIndex[high] || cari <arrIndex[low] )
{
Console.WriteLine("data tidak di temukan");
}
else
{
do
{
//perkiraan
posisi = low + ((high-low)*(cari-arrIndex[low]))/(arrIndex[high]-arrIndex[low]);
Console.WriteLine(posisi);
if (arrIndex[posisi]==cari)
{

ketemu= true;

}
else if (arrIndex[posisi]<cari)
{
low = posisi+1;
}
else
high = posisi-1;
}
while ((arrIndex[low]<= cari) && (arrIndex[high]>= cari) && (ketemu == false));
if (ketemu == true)
{
Console.WriteLine("\nData ditemukan");
Console.WriteLine("\nData          : {0}", data[posisi]);
Console.WriteLine("\nIndex         : {0}", arrIndex[posisi]);

Console.WriteLine("\nDitemukan");
}
else
{
Console.WriteLine("\nDak ketemu");
}
}
Console.Write("\nApakah Anda ingin Mengulang (y/t)? ");
ulang = Console.ReadLine();
}
while (ulang == "y" || ulang == "Y");

Console.ReadLine();
}
}
}

Inilah hasilnya cekidot😛

Dan hasil yang tidak ditemukan cekidot😛

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s