Given A[]={3, 1, 4, 5, 8, 9, 5, 7,10, 12}, write an element search algorithm. If the element is found , return its position in the array , otherwise return 0.
example:
the position of 3 is 1
the position of 5 is 4
#include
/*//===================================================
// Find an element in an array,
// n is the length of the array, x is the element to be found in the array
// if the search is successful, return the position of x in the array,
// otherwise return 0
//===================================================*/
int FindElement(int a[], int n, int x)
{
//***complete the function
}
void main()
{
int A[] = { 1, 3, 5, 8, 9, 5, 7,10, 12 };
int e;
int RetVal;
printf("Please input an integer number \n")
scanf("%d", &e);
RetVal= FindElement (A, sizeof(A)/sizeof(A[0]), e);
if(RetVal)
printf("The position of the element is %d\n", RetVal);
else
printf("The element doesn't exist in the array!\n");
}