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

can it be in programming language C, thanks 3. (20 pt) Write a function count_co

ID: 3743173 • Letter: C

Question

can it be in programming language C, thanks

3. (20 pt) Write a function count_common (int A, int B[, int nA, int nB) which takes two ID arrays of integers and their sizes as parameters, and then counts the number of common numbers in both array s. Assume that the numbers in each array are unique and sorted from smallest to largest. For example, if we have int AI61, 2, 3, 6, 7, 9; int BI51-1, 3, 4, 6, 8) int ni Then when we call your function as ncount common (A, B, 6, 5) it should return 3 because we have three common numbers (1, 3, 6) in both A and B

Explanation / Answer

#include<stdio.h>
int count_common(int A[],int B[],int nA,int nB)
{
int i=0,j=0,count=0;
for(i=0;i<nA;i++)
{
for(j=0;j<nB;j++)
if(A[i]==B[j]&&A[i]<=B[j])
count++;
}
return count;
}
int main()
{
int i,n,m;
printf("Enter Size of Array A :");
scanf("%d",&n);
printf("Enter Size of Array B :");
scanf("%d",&m);
int A[n], B[m];
printf("Enter elements in array A :");
for(i=0;i<n;i++)
scanf("%d",&A[i]);
printf("Enter elements in array B :");
for(i=0;i<m;i++)
scanf("%d",&B[i]);
printf("Number of Common elements in array :%d",count_common(A,B,n,m));
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote