- #1
dect117
- 25
- 1
Homework Statement
Write a function that finds if three arrays of integers are identical. The arrays are identical when they have the same values at the same indices. Below are two samples outputs.
Homework Equations
N/A
The Attempt at a Solution
I decided to compare the arrays using a for-loop. I feel like that's a messy way to go about it but I'm not really sure how else I can make it work. Here's my code.
Code:
#include <stdio.h>
#define SIZE 5
int main () {
int i, x, arr1[SIZE], arr2[SIZE], arr3[SIZE];
printf ("Array A: ");
for (i=0; i<SIZE; i++)
scanf ("%d", &arr1[i]);
printf ("Array B: ");
for (i=0; i<SIZE; i++)
scanf ("%d", &arr2[i]);
printf ("Array C: ");
for (i=0; i<SIZE; i++)
scanf ("%d", &arr3[i]);
for (i=0; i<SIZE; i++){
if (arr1[i]==arr2[i] && arr2[i]==arr3[i]) {
x==1;
}
else if(!(arr1[i]==arr2[i] && arr2[i]==arr3[i])) {
x==2;
break;
}
}
if (x==1)
printf ("\nThese arrays are identical!");
else if (x==2)
printf ("\nThese arrays are not identical!");
return 0;
}