Answer:
int withinArray(int * intArray, int size, int * ptr) {
if(ptr == NULL) // if ptr is NULL return 0
return 0;
// if the size of intArr is zero
if(size == 0)
return 0; // not found
else
{
if(*(intArray+size-1) == *(ptr)) // check if (size-1)th element equals ptr
return 1; // return positive indication
return withinArray(intArray, size-1,ptr); // call function recursively with size-1 elements
}
}
Explanation:
This is the complete part of the program.
Refer to the explanation
Define the function square_all() that receives a list of integers. This function should return a new list containing the square values of all integers found within the provided list.
def square_all(num_list):
#Initiate an empty list to store results.
sq_list = []
#Iterate through the length of the list.
for index in range(0, len(num_list)):
#Calculate the square of the current value and add it to the result list sq_list.
sq_list.append(num_list[index] * num_list[index])
#Return the squared values of all integers in num_list.
return sq_list
#Declare and initialize a list of integers.
intList = [2, 4]
#Invoke the square_all() function and pass the above list as an argument. Show the returned list.
print(square_all(intList))
The code is implemented using the Java programming language. This program effectively calculates the distance between two points based on the formula provided.