受困于字符型的问题
请教一下,怎么将如下的编码改成图片中的要求?对于这节的知识点有点迷糊。
// declare functions
// note there are two functions declared
float sum1(float array[], int num_elements);
float sum2(float *a, int num_elements);
// define function
float sum1(float array[], int num_elements)
{
float arraysum = 0.;
int i;
for (i=0; i<num_elements; i++)
{
arraysum = arraysum + array[i];
}
// a test, change last element array[num_elements-1] = 0.;
return arraysum;
}
//define function
float sum2(float *a, int num_elements)
int main()
{
float input[4];
float sum;
printf("enter four floats\n");
scanf("%f %f %f %f",&input[0],&input[1],&input[2],&input[3]);
printf("last element is %f\n",input[3]);
// call function 1
sum = sum1(input,4);
printf("array sum = %f\n",sum);
printf("last element is %f\n",input[3]);
// call function 2
sum = sum2(input,4);
printf("array sum = %f\n",sum);
return 0;
}