This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Tampilkan postingan dengan label Program Binary Search. Tampilkan semua postingan
Tampilkan postingan dengan label Program Binary Search. Tampilkan semua postingan

Kamis, 28 Maret 2013

Program Binary Search




#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#pragma hdrstop
#pragma argused

using namespace std;

int main(int argc, char *argv[])
{
int a;
int X,i,j,k,p;
int L[10] = a;
cout<<"Masukkan Data"<<a;
if(L[0]<L[9]){
printf("Data Terurut Menaik \n");
        p=0;
        }
else{
printf("Data Terurut Menurun \n");
             p=1;
             }

printf("Data yang akan dicari =");
scanf("%d", &X);
    i=0;
    j=9;
do{
        k=(i+j)/2;
if(p==0){
if(L[k]==X){
printf("Data ditemukan diElemen %d",k);
getch();
return 0;
                             }
else if (L[k]<X){
                                  i=k;     }   else{    j=k;    }    }
else{        if(L[k]==X){                         printf("Data diTemukan dieleme %d",k);
getch();
return 0;
                         }
else if(L[k]>X){
                  i=k;
                  }        else{     j=k;      }
             }}
while(k!=0);
printf("Data Tidak diTemukan");
system("PAUSE");
return EXIT_SUCCESS;
}