hopingsteam

Untitled

Apr 4th, 2020
279
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include    <iostream>
  2.  
  3. using namespace std;
  4.  
  5. float evaluareItr(unsigned int n, float coef[], unsigned int x)
  6. {
  7.     float val = 0.0;
  8.     for(int i = 1; i <= n + 1; i++)
  9.         val = val * x + coef[i];
  10.     return val;
  11. }
  12.  
  13. float evaluare(unsigned int n, float coef[], unsigned int x)
  14. {
  15.     if(n == 1)
  16.         return coef[1];
  17.     return coef[n] + x * evaluare(n-1, coef, x);
  18. }
  19.  
  20. int cautBin(int x, int b[], int m)
  21. {
  22.     int Sol = -1, Left = 0,  Right = m;
  23.     while(Left <= Right)
  24.     {
  25.         int Mid = (Left + Right) / 2;
  26.         if(b[Mid] == x)
  27.         {
  28.             Sol = Mid;
  29.             break;
  30.         }
  31.         if(b[Mid] > x)
  32.             Right = Mid - 1;
  33.         if(b[Mid] < x)
  34.             Left = Mid + 1;
  35.     }
  36.     return Sol;
  37. }
  38.  
  39. void subpctb(int a[], int n, int b[], int m, int c[], int &k)
  40. {
  41.     for(int i = 0; i < n; i++)
  42.     {
  43.         int el = a[i];
  44.         int rez = cautBin(el, b, m);
  45.         if(rez != -1)
  46.             c[k++] = b[rez];
  47.     }
  48. }
  49.  
  50. int main()
  51. {
  52.     int a[10005] = {5, -7,-2, 3};
  53.     int b[10005] = {-2, 3, 5, 7, 8};
  54.     int c[10005];
  55.     int n = 4, m = 5, k = 0;
  56.    
  57.     subpctb(a, n, b, m, c, k);
  58.  
  59.     for(int i = 0; i < k; i++)
  60.         cout << c[i] << " ";
  61.     return 0;
  62. }
RAW Paste Data