Can any one tell me how to check if the elements of two arrays are same? in c

i can't write code for you . But i can just give the idea .

just decalre 2 arrays like a[10] and b[10] assign values to them.And create one more variable of boolean type assign it a value false(Actually i am working with very old and also not good compiler which is TurboC++, there is nothing like bool.). So if you also working on TurboC++ compiler then i think you should create a integer type variable assign 0 to it.
then check each element of array with == operator.When condition is found true then assign True Or 1 to the variable.When you find the result of == to be false then simply assign False Or 0 to the variable and break the loop.

at last check if the variable contain True Or 1 , its mean both are same And Arrays won't be same when the variable contain False or 0.

Actually i am not sure whether c programing support bool data type or not. if it does not support then you can just assign 0 or 1 for False and True respectively.

now , you can do with it.

Edited 3 Years Ago by Learner010

i am glad to see that somebody is really learning here.
if you really feel that the above explanation help you then mark solved this discussion

you can take two arrays and check the condition a[i]==b[j] within 2 for loops.one will be i=o i<size of 1st array i++ and within this j=0 j<=i j++
and in these 2 loops you can check the condition a[i]==b[j] and print elements are same or else come out of loop and print they are not same.

you can also do it without a loop by calling memcmp(), which compares two arrays byte-by-byte.

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

if( memcmp(a,b,sizeof(a)) == 0)
{
   printf("They are the same\n");
}
else
{
   printf("They are different\n");
}

Edited 3 Years Ago by Ancient Dragon

Comments
Ahh the simple solution. Awesome
This question has already been answered. Start a new discussion instead.