#include "stdio.h"
#include "conio.h"
#include "iostream.h"
void main()
{
clrscr();
int data[8] = {8,10,6,-2,11,7,1,100};
int cari;
int flag=0;
cout<<"\n";
cout<<"\tSequential Searching \n";
cout<<"\t-------------------- \n\n";
printf(" Masukkan data yang ingin dicari = ");scanf("%d",&cari);
for(int i=0;i<8;i++)
{
if(data[i]==cari) flag=1;
}
if (flag==1) printf("\n\n Data Ada \n");
else printf("\n\n Data Tidak Ada\n");
getch();
}
Apabila ada kesalahan dalam diatas , Silahkan download yang ini :
http://www.mediafire.com/?435y8fnand22fdf
Senin, 04 Juni 2012
Binary Searching
#include "stdio.h"
#include "conio.h"
#include "iostream.h"
#include "stdlib.h"
void main()
{
clrscr();
int data[9]= {3,9,11,12,15,17,23,31,35};
int l,r,m;
int n=9;
int cari=17;
cout<<"\n";
cout<<"\tBinary Searching \n";
cout<<"\t---------------- \n";
l=0;
r=n-1;
int ktm=0;
while(l<=r && ktm==0)
{ m=(l+r)/2;
printf("\n\tData Tengah %d \n",m);
if(data[m] == cari) ktm=1;
else if(cari < data[m])
{
printf("\n\tCari Dikiri \n");
r=m-1;
}
else
{ l=m+1;
printf("\n\tCari Dikanan \n");
}
}
if (ktm=1) printf("\n\n Data yang dicari sudah Ditemukan\n");
else printf("\n\n Data yang dicari Tidak Ditemukan\n");
getch();
}
Apabila ada kesalahan running , silahkan download disini :
http://www.mediafire.com/?jrsoknz1wx2wo4h
#include "conio.h"
#include "iostream.h"
#include "stdlib.h"
void main()
{
clrscr();
int data[9]= {3,9,11,12,15,17,23,31,35};
int l,r,m;
int n=9;
int cari=17;
cout<<"\n";
cout<<"\tBinary Searching \n";
cout<<"\t---------------- \n";
l=0;
r=n-1;
int ktm=0;
while(l<=r && ktm==0)
{ m=(l+r)/2;
printf("\n\tData Tengah %d \n",m);
if(data[m] == cari) ktm=1;
else if(cari < data[m])
{
printf("\n\tCari Dikiri \n");
r=m-1;
}
else
{ l=m+1;
printf("\n\tCari Dikanan \n");
}
}
if (ktm=1) printf("\n\n Data yang dicari sudah Ditemukan\n");
else printf("\n\n Data yang dicari Tidak Ditemukan\n");
getch();
}
Apabila ada kesalahan running , silahkan download disini :
http://www.mediafire.com/?jrsoknz1wx2wo4h
Langganan:
Postingan (Atom)