I need to make simple program that makes new array which is made of sqrt-ed elements from first array. I must write elements of new array in main. I tried to debug my code, and variables x
and y
are displaying good numbers (I initialized them only so I can watch progress on debugger), but when I try to write elements of my new array, its showing some weird numbers. Can some good soul explain me what I am doing wrong ?
void returnSqrtArrayt(int* myArray, int length, double** newArray)
{
int i;
double x, y;
double* p;
double* arraySqrt=(double*)malloc(length*sizeof(double));
for(i=0;i<length;i++)
{
x=*myArray;
*arraySqrt=sqrt(x);
y=*arraySqrt;
myArray++;
arraySqrt++;
}
*newArray=arraySqrt;
p=arraySqrt;
for(i=0;i<length;i++)
{
printf("%e\n",*p);
p++;
}
printf("\n");
}
void main()
{
int myArray[5]={4,2,16,4,81};
int length=sizeof(myArray)/sizeof(int);
int i;
double* newArray;
returnSqrtArrayt(myArray, length, &newArray);
for(i=0;i<length;i++)
{
printf("%e\n",*newArray);
newArray++;
}
}