46.0k views
2 votes
Write the definition of a function, isreverse, whose first two parameters are arrays of integers of equal size, and whose third parameter is an integer indicating the size of each array. the function returns true if and only if one array is the reverse of the other. ("reverse" here means same elements but in reverse order.)

1 Answer

5 votes

Answer:

#include <iostream>

int isreverse(int a[], int b[], int size)

{

for (int i = 0; i < size; i++) {

if (a[i] != b[size - i - 1])

{

return 0;

}

}

return 1;

}

int main()

{

int first[] = { 2, 5, 7, 8, 15 };

int second[] = { 15, 8, 7, 5, 2};

int third[] = { 1, 2, 3, 4, 5 };

printf("First is %sthe reverse of second.\\", isreverse(first, second, 5) ? "": "NOT ");

printf("Second is %sthe reverse of third.\\", isreverse(second, third, 5) ? "" : "NOT ");

}

Step-by-step explanation:

Assuming you are looking for a C/C++ solution...

User Charlie G
by
6.4k points