/*2.编写一个程序,初始化一个 double 数组,然后把数组内容复制到另外两个数组(3 个数组都需
要在主程序中声明)。制作第一份拷贝的函数使用数组符号。制作第二份拷贝的函数使用指针符号,并使用
指针的增量操作。把目标数组名和要复制的元素数目做为参数传递给函数。也就是说,如果给定了下列声
明,函数调用应该如下面所示:
double source [5]={1.1, 2.2, 3.3, 4.4, 5.5};
double targetl[5];
double target2 [5];
copy_arr (source, target1, 5);
copy_ptr (source, target1,5);*/
#include<stdio.h>
#include<stdlib.h>
void copy_arr(double[], double[], int);
int main()
{
double source[7] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7};
double target1[3] = {0};
printf("before: target1:%.1lf %.1lf %.1lf\n",target1[0], target1[1], target1[2]);
copy_arr (source + 2, target1, 3);
printf("\nnow: target1:%.1lf %.1lf %.1lf\n",target1[0], target1[1], target1[2]);
system("pause");
return 0;
}
void copy_arr (double s[], double t1[], int n)
{
int i;
for (i = 0; i < n; i++)
t1[i] = s[i];
}