In: Computer Science
In C programming:
Write a program that initializes an array-of-double and then copies the contents of the array into another arrays. To make the copy, use a function with array notation. This function takes two arguments the name of the target array and the number of elements to be copied. That is, the function calls would look like this, given the following declarations:
double source[5] ={1.1, 2.2, 3.3., 4.4, 5.5};
double target1[5];
double target2[5];
copyarr(source, target1, 5);
ANSWER: Here I am giving you the code and output before going to dislike please comment on your problem I will definitely help you. If it is helpful please like it.
CODE:
#include <stdio.h>
void copyarr(double source[], double target1[], int size){
int i;
for(i=0;i<size;i++){
target1[i]=source[i];
}
}
int main()
{
double source[5] ={1.1, 2.2, 3.3, 4.4, 5.5};
double target1[5];
double target2[5];
copyarr(source, target1, 5);// first time calling function
copyarr() to copy source array to target1 array.
int i;
printf("target1 array content after copy from source
array:\n");
for(i=0;i<5;i++){
printf("%.1lf ",target1[i]);
}
copyarr(source, target2, 5);// second time calling function
copyarr() to copy source array to target1 array.
printf("\ntarget2 array content after copy from source
array:\n");
int j;
for(j=0;j<5;j++){
printf("%.1lf ",target2[j]);
}
return 0;
}
OUTPUT: