i have a problem :

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.)

this is the code i wrote:

``````bool isReverse(int x[],int y[],int z){
int i,b;
for(i=0;i<z;i++)
if(x[i]==y[z-i-1])
b=1;
else b=0;
return b;
}``````

i thought i did it right but its not and i'm not sure whats wrong. one of the error messages i was given is:

It seems that your function fails to check the ends of the arrays. Please revise your code.

i'm not sure what that mean. can somebody help me. thanks in advance.

## All 7 Replies

>It seems that your function fails to check the ends of the arrays.

That doesn't look like a compiler error. Did your teacher tell you this?

yea thats not a compiler error message. you could say that its a remark, i guess the code i wrote doesnt do what it wants me to. but i dont understand what it wants. what i wrote looks right to me, but it says its wrong so its wrong.

yea thats not a compiler error message. you could say that its a remark, i guess the code i wrote doesnt do what it wants me to. but i dont understand what it wants. what i wrote looks right to me, but it says its wrong so its wrong.

Is "it" a online judge? If so then post the question.

no, you just write the code for what it wants then submit it, if its right then you pass and if its wrong then you do it again thing.

what is "it"?

Suppose you have two arrays:

``````tab1[]={1,1,1};
tab2[]={1,0,1};``````

First iteration: `tab1[0]==tab2[2] =>b=1;` second iteration: `tab1[1]!=tab2[1] =>b=0; (so far, so good)` third iteration: `tab1[2]==tab1[0] =>b=1 (again!)` The loop is over and you return b, your function says that arrays are equal which is not true.
Solution: end the loop after second iteration (at the first time, when find difference between arrays). Use `break`

Suppose you have two arrays:

``````tab1[]={1,1,1};
tab2[]={1,0,1};``````

First iteration: `tab1[0]==tab2[2] =>b=1;` second iteration: `tab1[1]!=tab2[1] =>b=0; (so far, so good)` third iteration: `tab1[2]==tab1[0] =>b=1 (again!)` The loop is over and you return b, your function says that arrays are equal which is not true.
Solution: end the loop after second iteration (at the first time, when find difference between arrays). Use `break`

thanks alot it worked. gonna take a bit to understand why but thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.