#include<iostream.h>
#include<conio.h>
int main()
{
void sortarray(int array[15],int size);
void mergearray(int ar1[15], int ar2[15], int ar3[30],int m ,int n);
int m, n ,ar1[15],ar2[15],ar3[30],array[15],size;
cout<<" Enter the size of the arrays "<<endl;
cin>>m>>n;
cout<<" Enter the elements of first array "<<endl;
for(int i=0;i<m;i++)
cin>>ar1;
cout<<" Enter the elements of second array "<<endl;
for(int j=0;j<n;j++)
cin>>ar2[j];
sortarray(ar1,m);
sortarray(ar2,n);
mergearray(ar1,ar2,ar3,m,n);
getch();
}//****************End of main
void sortarray(int array[15],int size)
{
int temp=0;
for(int i=0;i<size;i++)
{
for(int j=i+1;j<size+1;j++)
{
if(array>array[j])
{temp=array;
array=array[j];
array[j]=temp;
}
}
}
}
void mergearray(int ar1[15],int ar2[15], int ar3[30] , int m ,int n)
{ if(m>n)
{
for(int i=0;i<n;i++)
{
if(ar1>ar2)
ar3=ar2;
else ar3=ar1;
}
for(int k=n;k<m;k++)
ar3[n]=ar1[n];
}
else
{
for(int i=0;i<m;i++)
{
if(ar1>ar2)
ar3=ar2;
else ar3=ar1;
}
for(int k=m;k<n;k++)
ar3[m]=ar1[m];
}
for(int k=0;k<m+n;k++)
cout<<ar3[k]<<"\t";
}
not getting the correct output .
i am basically trying to make a prog to accept the elements of two arrays then merging the two arrays and getting it sorted .
then printing it.there are no compile errors and the second array gets sorted while after that wat i get is a bunch of arbitrary values. plz indiate the faults.