Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define ARRAY_SIZE 5
- using namespace std;
- bool compare(int x[], int y[], int size);
- int main(void)
- {
- int a1[ARRAY_SIZE] = {1, 2, 3, 4, 5};
- int a2[ARRAY_SIZE] = {1, 2, 3, 4, 5};
- int a3[ARRAY_SIZE] = {1, 1, 1, 1, 1};
- if ( compare(a1, a2, ARRAY_SIZE) )
- cout<<"Arrays a1 and a2 are equal\n";
- else
- cout<<"Arrays a1 and a2 are not equal\n";
- if ( compare(a1, a3, ARRAY_SIZE) )
- cout<<"Arrays a1 and a3 are equal\n";
- else
- cout<<"Arrays a1 and a3 are not equal\n";
- return 0;
- }
- bool compare(int x[], int y[], int size)
- {
- bool flag= true; // assume 2 arrays are equal
- //version 1
- /* for(int i = 0; i < size; i++)
- if(x[i] ==y[i])
- ; // DO NOTHING SINCE ASSUME 2 ARRAYS ARE EQUAL INITIALLY
- else
- flag = false;
- */
- //version 2
- /*for(int i = 0; i < size; i++)
- if (x [i] != y[i])
- flag = false;
- */
- //version 3
- int i= 0;
- while ( i < size && flag != false)
- {
- if if (x [i] != y[i])
- flag = false;
- i++;
- }
- return flag;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement