#include <stdio.h>
#include <stdlib.h>
#include <time.h>
double *generate_array(int value) {
double *array = malloc(sizeof(double) * value);
for (int i = 0; i < value; i++){
array[i] = (double)rand() / RAND_MAX;
}
return array;
}
double *clone_array(double *array, size_t size) {
double *new_array = malloc(sizeof(double) * size);
for(size_t i = 0; i < size; ++i) {
new_array[i] = array[i];
}
return new_array;
}
int main()
{
srand(time(NULL));
size_t array_length = 10;
double *array = generate_array(array_length);
double *new_array = clone_array(array, array_length);
new_array[3] = 0;
for (size_t i = 0; i < array_length; i++){
printf("%lf\n", array[i]);
}
printf("\n");
for (size_t i = 0; i < array_length; i++){
printf("%lf\n", new_array[i]);
}
free(new_array);
free(array);
return 0;
}
|