Write a function called matches that takes two int arrays and their respective sizes, and returns the number of consecutive values that match between the two arrays starting at index 0. Suppose the two arrays are {3, 2, 5, 6, 1, 3} and {3, 2, 5, 2, 6, 1, 3} then the function should return 3 since the consecutive matches are for values 3, 2, and 5.
in C++
Im confused how to start this, any hints are great and keep it as simple as possible please!
#include <iostream> using namespace std; int matches(int arr1[], int size1, int arr2[], int size2){ int i = 0, count = 0; while(i<size1 && i<size2){ if(arr1[i]==arr2[i]){ count++; } i++; } return count; } int main() { int arr1[] = {3, 2, 5, 6, 1, 3}; int arr2[] = {3, 2, 5, 2, 6, 1, 3}; cout<<matches(arr1,6,arr2,7)<<endl; return 0; }
3
Get Answers For Free
Most questions answered within 1 hours.