this is the exercise i am having difficulty with:
Write a function that prints the values stored in an array of doubles containing n elements. The
function prototype is:
void print_array(double x[], int n);
The required format for the output is [elem0 elem1 elem2 ... elemn-1]; that is, a list
of values enclosed in square brackets, with one space between each pair of values. There miust
be no spaces between the '[' and the first value, or between the last value and ']'. Here is an
example: [1.0 5.2 -3.7 4.9].
Write a main function that exercises print_array.
and this is the code i have so far:
i believe that my code is correct, but an not sure how to test it. i am having problems with the last part of the problem "Write a main function that exercises print_array."Code:void print_array (double x[], int n){ int i=0; for (x[i];i<n;i++){ if (x[0]){ printf("[%d ", x[0]); } else if (x[n-1]) { printf("%d]\n",x[n-1]); } else { printf("%d ", x[i]); } } }
Anyway, thanks in advanced!!