Page 136 - Modul Algoritma dan Pemrograman Dasar
P. 136

Contoh Program :


                           1.  #include <iostream>
                           2.  #include <stdio.h>
                           3.  #include <iomanip>
                           4.
                           5.  using namespace std;
                           6.
                           7.  int main()
                           8.  {
                           9.      int a[11] = {12, 17, 10, 5, 15, 25, 11, 7, 25, 16, 19};
                           10.     int i, n, flag;
                           11.     cout << " ===== Contoh Sequential Search =====" << endl <<
                               endl;
                           12.     cout << " Masukkan Bilangan Integer : ";
                           13.     cin >> n;
                           14.     cout << endl;
                           15.     for (i=0; i<11; i++){
                           16.         cout << setw (5) << a[i];
                           17.     }
                           18.     cout << endl;
                           19.
                           20.     i = 0;
                           21.     flag = 0;
                           22.     while (i<=10){
                           23.         if (a[i] == n){
                           24.             flag++;
                           25.         }
                           26.         i++;
                           27.     }
                           28.     if (flag > 0){
                           29.         cout << "\n Bilangan Ditemukan ";
                           30.         cout << "\n Terdapat " << flag << " Bilangan yang
                               Sama";
                           31.     } else {
                           32.         cout << "\n Bilangan Tidak Ditemukan ";
                           33.     }
                           34.     return 0;
                           35. }











                                                                                                    131
   131   132   133   134   135   136   137   138   139   140   141