I have two arrays, and I need to merge them into one list. They don't have to be sorted or anything, but I don't know how to code it.
Here's what I have written:
Code
#include <iostream>
using namespace std;
int main()
{
int a[10]={3,12,45,59,2,38,99,24,81,17};
int b[5]={6,81,72,28,59};
int maxa = a[0];
int mina = a[0];
int maxb = b[0];
int minb = b[0];
double suma = 0;
double sumb = 0;
double averagea = 0;
double averageb = 0;
for (int i=0; i < 10; i++){
if( maxa <= a[i] )
maxa = a[i];
if ( mina >= a[i] )
mina = a[i];
suma+=a[i];
averagea = suma/10;
cout << "Array 1: Average: " << averagea << endl;
cout << "Array 1: Smallest Array Element: " << mina << endl;
cout << "Array 1: Largest Array Element: " << maxa << endl;
}
for (int j=0; j < 5; j++){
if( maxb <= b[j] )
maxb = b[j];
if ( minb >= b[j] )
minb = b[j];
sumb+=b[j];
averageb = sumb/5;
cout << "Array 2: Average: " << averageb << endl;
cout << "Array 2: Smallest Array Element: " << minb << endl;
cout << "Array 2: Largest Array Element: " << maxb << endl;
}
system("pause");
return 0;
}
This post was edited by King3r on Sep 26 2013 03:45pm