4. (Extra credit: 5 pts) The following is the prototype for a function: void fac
ID: 3699454 • Letter: 4
Question
4. (Extra credit: 5 pts) The following is the prototype for a function: void factors(int xI 1, int yl l. int YNI 1, int n); The function takes three arrays of size n: x, y, and YN. Arrays x and y contain d ata and array YN is At each index, find the largest common factor of the values in x and y and store the the values in x and y are equal, the largest common factor is the value. If the larger value initially empty. result in YN. If is divisible by the smaller value,S?Rthe largest common factor is the smaller valueExplanation / Answer
The code would be
void factors(int x[],int y[],int yn[],int n)
{
int i;
for(i=0;i<n;i++)
{
int min=x[i]>y[i]?y[i]:x[i];
if(x[i]%y[i]==0)
yn[i]=y[i];
else if(y[i]%x[i]==0)
yn[i]=x[i];
else
{
int j=1;
for(j=1;j<min;j++)
if(x[i]%j==0 && y[i]%j==0)
yn[i]=j;
}
}
}
Do give a thumbs up
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.