Quirinus

LinearSearch_2

Oct 19th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int trazeni_broj = 30;
  7.     int pojavljuje = 0;
  8.    
  9.     int duljina = 51;
  10.     int polje[duljina];
  11.     for (int i = 0; i < duljina; i++)
  12.     {
  13.         polje[i] = i+10;
  14.         cout << "Index: " << i << "  Vrijednost: " << polje[i] << endl;
  15.     }
  16.     polje[50] = 30;
  17.  
  18.     for (int i = 0; i < duljina; i++)
  19.     {
  20.         if (polje[i] == trazeni_broj)
  21.         {
  22.            pojavljuje++;
  23.         }
  24.     }
  25.  
  26.     cout << "Broj " << trazeni_broj << " se pojavljuje " << pojavljuje << " puta." << endl;
  27.  
  28.  
  29.     system("PAUSE");
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment