Guest User

Untitled

a guest
Jan 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define LENGTH 20
  4.  
  5.  
  6. int interpolationSuche (int key, int* values)
  7. {  
  8.     int x=0;
  9.     int l=0;
  10.     int r=LENGTH-1;
  11.     while (values[x]!=key)
  12.            {
  13.                 x=l+((key-values[l])/(values[r]-values[l]))*(r-l);
  14.                  if( values[x] == key)
  15.                  {
  16.                      return x;
  17.                  }
  18.                  
  19.                  else if (values[x] >= key)
  20.                  {
  21.                       l++;
  22.                  }
  23.                  
  24.                  else if (values[x] <=key)
  25.                  {
  26.                       r--;
  27.                  }
  28.          }
  29. }                                        
  30. int main()
  31. {
  32.     int Zahl;
  33.     int position;
  34.     int array[20]={2,3,9,13,23,33,45,50,51,67,78,80,94,100,102,116,121,169,198,200};
  35.     printf("Geben Sie die Zahl ein, die Sie suchen\n");
  36.    
  37.     scanf("%d", &Zahl);
  38.    
  39.     position = interpolationSuche ( Zahl, array);
  40.    
  41.     printf("Ihre %d Zahl befindet sich an Stelle %d", Zahl,position);
  42.  
  43.     system("pause");
  44. }
Add Comment
Please, Sign In to add comment