#include <iostream>
usingnamespace std;
int main()
{
int arr [2] [2];
int ar [2] [2];
int num;
int temp [3] [1];
cout << "enter the numbers in your first array:"<< endl;
for (int i=0; i<2; i++)
{
for (int t=0; t<2; t++)
{
cout << i << "," << t << ":";
cin >> arr [i][t];
}
}
cout << "enter the numbers in your second array:"<< endl;
for (int i=0; i<2; i++)
{
for (int t=0; t<2; t++)
{
cout << i << "," << t << ":";
cin >> ar [i][t];
}
}
num=arr[0][1];
if (arr[0][0]<num){temp[0][0]=num;temp[0][1]=arr[0][0];};
num=arr[0][1];
if (arr[0][0]>num){temp[0][0]=arr[0][0];temp[0][1]=num;};
num=arr[1][0];
if (arr[1][1]<num){temp[1][0]=num;temp[1][1]=arr[1][1];};
num=arr[1][0];
if (arr[1][1]>num){temp[1][0]=arr[1][1];temp[1][1]=num;};
num=ar[0][1];
if (ar[0][0]<num){temp[2][0]=num;temp[2][1]=ar[0][0];};
num=ar[0][1];
if (ar[0][0]>num){temp[2][0]=ar[0][0];temp[2][1]=num;};
num=ar[1][0];
if (ar[1][1]<num){temp[3][0]=num;temp[3][1]=ar[1][1];};
num=ar[1][0];
if (ar[1][1]>num){temp[3][0]=ar[1][1];temp[3][1]=num;};
for (int o=0; o<4; o++)
{
for (int d=0; d<2; d++)
{
cout<<temp[o][d]<<",";
}
}
return 0;
}
What do you mean by "the results are messed up"? Do they look like a swastika? Are they just 2 decimal places off from the meaning of life? Are they your family's social security numbers but backwards? You need to be specific.
Here is a simple program to do what you want.
When you say merges, there are several ways to do that so i just choose 1 for this example.
Also, a 2D array can be sort in many ways. consider a 2d array array[i][j] .
You could sort by major index i or by sub index j .
I choose to sort all elements in the order they are in the array.