AddO1f

Algor1_2

Mar 20th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "iostream"
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int mas[100];
  9.     int m = 0;
  10.     int n1,x,n;
  11.     cout << "razmer:";
  12.     cin >> n1;
  13.     cout << "massiv:";
  14.     for (int i = 0;i < n1;i++)
  15.     {
  16.         cin >> mas[i];
  17.     }
  18.     for (;;)
  19.     {
  20.         n = n1;
  21.         m = 0;
  22.         cout << "poisk:";
  23.         cin >> x;
  24.         int k = (n + m) / 2;
  25.         while (mas[k] != x)
  26.         {
  27.             if (mas[k] > x) n = k;
  28.             else m = k;
  29.             k = (n + m) / 2;
  30.             if (n - m == 1) { cout << "ne naideno" << endl << endl; break; }
  31.         }
  32.         cout << k << endl<<endl;
  33.     }
  34.     system("pause");
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment