Hi

I have an assignment which requires me to do the following:

Required to write a function that finds an integer in an array and returns

its corresponding index. The function must be called findNumber. It must have FOUR parameters:

The first parameter is the array to be searched

The second parameter is the integer to be found within the array

The third parameter is the size of the array

The fourth parameter is an integer that indicates whether the array is sorted. A value of 1

means the array is sorted; a value of zero means the array is not sorted.

__________________________________________________ __

Since a function can only return one value(To return the position of a required integer in an array in this instance) I have tried to make use of pointers to try and return a value stating whether the array is sorted or not.

This is my code : (It compiles perfectly but it does not produce any outputs)

Code:#include <stdio.h> #define SIZE 10 size_t findNumber(int *sort, const int array[],int key,size_t size); int main(void){ int a[SIZE]; size_t x; int search_key; size_t element; int isSorted=0; for (x = 0;x < SIZE; ++x){ a[x]=2*x; } puts("Enter the integer you are looking for:"); scanf_s("%d", &search_key); element= findNumber(&isSorted,a,search_key,SIZE); if (isSorted==1) { printf("Array is sorted"); } else{ printf("Array is not sorted"); } printf("Your value has been found in element %d \n",element); return 0; } size_t findNumber(int *sort,const int array[],int key,size_t size){ size_t n; for (n = 9; n < SIZE; --n){ if (array[n] >= array[n-1] || array[n] <= array[n-1] ){ *sort=1; } *sort=0; } for (n = 0; n < size; ++n) { if (array[n] == key) { return n; } return -1; } }

______________________________________

Will appreciate any help to help solve this problem