Program Pencarian Liniear

#include <iostream>
#define UKURAN 100
using namespace std;
int pencarianLinier(int array[], int kunci, int ukuran){
    int i,n;
    double ketemu;
    ketemu=false;
    n=1;
    while(n< ukuran && !ketemu){
             if(array[i]==kunci){
             ketemu = true;
             i=n;
             }
             else {n=n+1;}
             n++;}
}
int main(){
    int a[UKURAN], x, kunciPencarian, elemen;
    for(x=0; x<= UKURAN-1; x++)a[x]= 2*x;
             cout<<"Bilangan yang mau dicari : ";
             cin>>kunciPencarian;
             elemen = pencarianLinier(a, kunciPencarian, UKURAN); cout<<endl;
    if(elemen != -1)
     cout<< kunciPencarian << " ditemukan pada posisi elemen ke- " <<elemen<<endl; 
    else
      cout<<kunciPencarian<<"Tidak Ada"<<endl;  
    system("PAUSE");
    return 0;
}
Posted in Uncategorized

komentar

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

calender lalu
April 2013
T W T F S S M
« Mar    
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

Information
081-917- 166-???
Lunch: 11am - 2pm
Dinner: M-Th 5pm - 11pm, Fri-Sat:5pm - 1am
%d bloggers like this: