hey guys i wrote this code and it keeps giving me an error which says that the program is writing to memory after the end of the heap. how can i fix this problem? thank you.
here is the code:
#include <iostream>
#include <ctime>
usingnamespace std;
void printarray (double A[], int n){
int i=0;
while (i<n){
cout<<A[i]<<' ';
i++;
}
return;
}
int main () {
int n;
int i=0;
int j=0;
double a=0;
double *x;
double temp=0;
srand (time(0));
cout<<"please enter the size of your first array of abscissas"<<endl;
cin>>n;
x = newdouble (n);
while (i<n){
a = rand ()% 101;
x[i]=a;
i++;
}
while (j<n){
int k=j+1;
while (k<n){
if(x[k]<x[j]){
temp = x[j];
x[j]=x[k];
x[k]=temp;
}
k++;
}
j++;
}
printarray (x,n);
delete x;
x=NULL;
return 0;
}