+ 1
c++ write a function that checks whether two arrays have the same elements in the same order
Hey, guys, I have an assignment that says write a function that checks whether two arrays have the same elements in the same order. bool equals(int a[], int a_size, int b[], int b_size). I cannot even start to do this one. can you guys give me any idea? seriously need help... thanks guys and I need cases 1. Build two arrays that are identical and your program produces the message claiming “Both arrays are the same”. 2. Build two arrays that are different and your program produces the message claiming “Two arrays are different”. 3. Each array should contain at least 10 elements.
2 odpowiedzi
+ 3
if (a_size != b_size) return false;
for(int i=0; i<a_size; i++)
if(a[i] != b[i]) return false;
return true;
+ 2
bool equals(int a[],int a_size,int b[],int b_size){
bool tmp = false;
if(a_size==b_size){
for(int i=0; i<a_size; i++){
if(a[i]==b[i]) tmp = true;
else{
tmp= false;
break;
}
}
}
return tmp;
}