مشكل در چاپ آرايه اي از نوع عدد صحيح
سلام
من به يه مشكل در برنامه ي زير برخوردم كه اگه لطف كنيد و بگيد واسه ي چي هست ممنون ميشم.
مشكل اينه كه در خط 50 بايد مقادير موجود در آرايه ي result ر روي مانيتور چاپ بشه ولي اگه برنامه رو اجرا كنين مي بينيد كه عددهايي منفي و غير منطقي بر روي مانيتور چاپ مي شود.
کد:
#include <iostream>
using namespace std;
int* sort(int* one,int* two,int of1,int of2)
{
int* result;
result = new int[of1 + of2];
int i = 0;
for(i = 0;i < of1;i++)
result[i] = one[i];
for(i = of1 - 1;i < of2;i++)
result[i] = two[i];
int item;
for(i = 0;i < (of1 + of2);i++)
for(int j = 0;j < (of1 + of2);j++)
if(result[j] > result[i])
{
item = result[i];
result[i] = result[j];
result[j] = item;
}
return result;
}
int main()
{
int* one,*two,*result,of1,of2;
cout <<"Enter offset of array one:";
cin>>of1;
cout <<"\nEnter offset of array two:";
cin>>of2;
one = new int[of1];
two = new int[of2];
for(int i = 0;i < of1;i++)
{
cout <<"\none["<<i<<"]:";
cin>>one[i];
}
for(int j = 0;j < of2;j++)
{
cout <<"\ntwo["<<j<<"]:";
cin>>two[j];
}
result = new int[of1 + of2];
int h = 0;
result = sort(one,two,of1,of2);
for(int k = 0;k < (of1 + of2);k++)
cout <<result[k];
return 0;
}
:11::11::11: