Write a function and prototype statement that accepts three parameters. The firs
ID: 667034 • Letter: W
Question
Write a function and prototype statement that accepts three parameters. The first two parameters are pointers to 1-D arrays of integers. You may assume that the two arrays have already been declared with initial values and are of equal size but you must show the declaration of the pointer variables. The third parameter is just an empty 1-D array of integers. Your function must contain statements that select all integer values that are equal between the arrays pointed to by the first two pointer parameters and assign those common values to the third array. Hint: Use nested loops.Explanation / Answer
// Header files
#include <iostream>
#include <string>
#include<array>
using namespace std;
//Function declaration
void equalvalue(int *arr1, int *arr2, int rpt[]);
int main()
{
int arr1[] = {1,5,3,4,2};
int arr2[] = {0,1,2,4,3};
int rpt[5]={};
equalvalue(arr1, arr2, rpt);
int ln=sizeof(rpt)/sizeof(int);
// Print the values
for(int l=0;l<ln;l++)
{
if(rpt[l]!=0)
cout<<rpt[l]<<endl;
}
getchar();
return 0;
}
//Function definition
// Method to find the repeated value and return the array value
void equalvalue(int *arr1, int *arr2, int rpt[])
{
int in=0;
// Loop to get the duplicate value and store it into array
for (int i1 = 0; i1 <=sizeof(arr1); i1++)
{
for (int j1 = 0; j1 <=sizeof(arr1); j1++)
{
if(arr1[i1]==arr2[j1])
{
rpt[in]=arr1[i1];
in++;
}
}
}
return;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.