Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to write a c programming function that takes in two arrays of size n, int

ID: 3670078 • Letter: I

Question

I need to write a c programming function that takes in two arrays of size n, int n, and int b. And the compares array 1 and array 2 to make sure there is at least b matching values in the same indexes and returns 1 if there are and zero if not.
Example N-4 Array 1: 1 2 5 6 Array 2: 1 4 2 3 B: 2
The function returns false because while there are two matching values 1&2 they are not in the same position I need to write a c programming function that takes in two arrays of size n, int n, and int b. And the compares array 1 and array 2 to make sure there is at least b matching values in the same indexes and returns 1 if there are and zero if not. I need to write a c programming function that takes in two arrays of size n, int n, and int b. And the compares array 1 and array 2 to make sure there is at least b matching values in the same indexes and returns 1 if there are and zero if not.
Example N-4 Array 1: 1 2 5 6 Array 2: 1 4 2 3 B: 2
The function returns false because while there are two matching values 1&2 they are not in the same position

Explanation / Answer

#include<stdio.h>

int compareArrays(int arr1[],int arr2[], int n, int b){
   int count=0,i;
   for(i=0; i<n; i++){
       if(arr1[i]==arr2[i])
           count++;
       }
   if(count == b)
       return 1;
   else
       return 0;
   }

int main(){
   int n = 4;
   int arr1[]={ 1, 2, 5, 6};
   int arr2[]={ 1, 4, 2, 3};
   int b=2;
  
   int status = compareArrays(arr1, arr2, n, b);
   if(status==1)
       printf("Equal ");
   else
       printf("Not Equal ");
   return 0;
   }