Write a function that takes in 3 arguments: a sorted array, size of the array, and an integer number. It should return the position where the integer value is found. In case the number does not exist in that array it should return the index where it should have been if it were present in this sorted array. Use pointer notation of arrays for this question.
#include <stdio.h> int find(int *arr, int size, int num) { int i; for (i = 0; i < size; ++i) { if (*(arr+i) >= num) { return i; } } return size; } int main() { int arr[] = {1, 3, 4, 7, 8, 10}; printf("%d\n", find(arr, 6, 0)); printf("%d\n", find(arr, 6, 1)); printf("%d\n", find(arr, 6, 2)); printf("%d\n", find(arr, 6, 3)); printf("%d\n", find(arr, 6, 4)); printf("%d\n", find(arr, 6, 10)); printf("%d\n", find(arr, 6, 15)); return 0; }
Get Answers For Free
Most questions answered within 1 hours.