diff --git a/dynamic_programing/longest_common_subsequence/C/a.out b/dynamic_programing/longest_common_subsequence/C/a.out new file mode 100755 index 0000000..4ea01e9 Binary files /dev/null and b/dynamic_programing/longest_common_subsequence/C/a.out differ diff --git a/search/interpolation_search/C/a.out b/search/interpolation_search/C/a.out new file mode 100755 index 0000000..b1d909d Binary files /dev/null and b/search/interpolation_search/C/a.out differ diff --git a/search/interpolation_search/C/interpolation.c b/search/interpolation_search/C/interpolation.c new file mode 100644 index 0000000..2265655 --- /dev/null +++ b/search/interpolation_search/C/interpolation.c @@ -0,0 +1,75 @@ +#include + +#define MAX 200 + +int interpolation_search(int a[], int bottom, int top, int item) + +{ + + int mid; + + while (bottom <= top) { + + mid = bottom + (top - bottom) * ((item - a[bottom]) / (a[top] - a[bottom])); + + if (item == a[mid]) + + return mid + 1; + + if (item < a[mid]) + + top = mid - 1; + + else + + bottom = mid + 1; + + } + + return -1; + +} + +/* End of interpolation_search() */ + + + +/* The main() begins */ + +int main() + +{ + + int arr[MAX]; + + int i, num; + + int item, pos; + + printf("\nEnter total elements (num< %d) : ", MAX); + + scanf("%d", &num); + + printf("Enter %d Elements in ascending order: ", num); + + for (i = 0; i < num; i++) + + scanf("%d", &arr[i]); + + printf("\nSearch For : "); + + scanf("%d", &item); + + pos = interpolation_search(&arr[0], 0, num - 1, item); + + if (pos == -1) + + printf("\nElement %d not found\n", item); + + else + + printf("\nElement %d found at position %d\n", item, pos); + + return 0; + +} \ No newline at end of file