Comparing elements in the same array
How do I write a function that will compare the elements in the array? Example: my array is 1, 2, 3, 4, 5.
I want to compare if
1 = 2
1 = 3
1 = 4
1 = 5
2 = 3
2 = 4
I tried using a for loop and nested for loop and I still can't seem to get it correct. Any help will be great;
Hope this helps
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
using namespace std;
int main()
{
int arr[5] = {1,2,3,4,5};
for(int i = 0; i < 5; i++)
{
for (int j = 1; j < 5; j++) {
cout << arr[i] << " "<< arr[j] << endl;
}
}
return 0;
}
|
Last edited on
Your question is so vague. Why would you compare if 1 = 2?
Topic archived. No new replies allowed.