Hi Guys,
I'm new to programming and new to this forum so hello everyone.
Can anyone point me in the right direction, and let me know where I'm going wrong in this code below.
I’m trying to match the numbers of two arrays and then print the numbers that are the same. My problem is this code prints all the integers of array_1 when it should be only printing the integers that match (10 20 40 50) it looks like the condition of the if statement is being ignored.
Code:
#include <stdio.h>
int main(void)
{
int array_1[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
int array_2[] = { 10, 20, 30, 40, 50, 6, 7, 8, 9, 10 };
int i;
int match;
i = 0;
/* Array_1 loops from element 0 to 9, comparing all elements of array_2 for a match */
for (i = 0; i < 10; ++i) {
if (array_1[i] == array_2[0] || array_2[1] || array_2[2] || array_2[3]
|| array_2[4] || array_2[5] || array_2[6] || array_2[7] || array_2[8]
|| array_2[9])
/* Print matches to screen */
{
match = array_1[i];
printf("Interger %d is a match\n", match);
}
}
return 0;
}