linear search algorithm

this isnt the entire program, just part the part im having trouble with , in which i try to search for the values from array2 in array1 and display the position. how do i send out the numbers from array2 into the other function?

int main()
{
const int SIZE=10;
int array1[SIZE];
const int SIZE2=5;
int array2[SIZE2];
int z=function2(array1,SIZE,?);


}

int function2(int a[], int b, int c)
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;


void read(int arr[], int size)
{
	for(int i=0; i<size; i++)
	{
		cout << arr[i] << " ";
	}
}


int main()
{
	int ar[] = {3,4,5,6};
	int size = 4;
	read(ar, 4);
	
return 0;
}
can you elaborate, I dont think that solves my problem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;


int read(int arr[], int size, int x)
{
	return arr[size-1]*x;
}


int main()
{
	int ar[] = {3,4,5,6};
	int size = 4;
	
	int  n = read(ar, 4, 100);
	
	cout << n; // 600
	
return 0;
}
im not sure if you understand my question correctly or if i just dont understand your response.
if were like this
1
2
3
4
5
6
7
8
9
int main()
{
const int size=10;
int array[size];

int z=function2(array,size,29); // instead of 29, i need to send the numbers from another array

}
int function2(int a[],int b,int c) // this part needs to stay like this  
Last edited on
your problem describing language is messed up. also your title does not reflect what you want.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;


int read(int arr[], int size, int x)
{
	return arr[size-1]*x;
}

int getVal () {
	return 25;
}

int main()
{
	int ar[] = {3,4,5,6};
	int size = 4;
	
	int  n = read(ar, 4, getVal());
	
	cout << n; // 150
	
return 0;
}
or, like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;


int read(int arr[], int size, int x)
{
	return arr[size-1]*x;
}


int main()
{
	int ar[] = {3,4,5,6};
	int size = 4;
	
	int anotherArray[] = {12,25,16,18,20};
	
	int  n = read(ar, 4, anotherArray[1] ); // send 2nd element of anotherArray
	
	cout << n; // 150
	
return 0;
}
what do you mean its messed up, my program is more in-depth, im just posting the part i dont understand . this assignment is about the linear search algorithm using two different arrays.
sorry about the title, changed it
Last edited on
i see you changed the topic name.

in which i try to find out where the index position the values in array1 are located at in array1.

don't you think its messed up?

haha wow i did not type that well, i meant search for the values from array2 in array1 and display the position
int n = read(ar, 4, anotherArray[1] ); // send 2nd element of anotherArray
^this is what you posted, instead of sending just one element, how do you send all of them
Last edited on
Topic archived. No new replies allowed.