I wanted to create a function that would print my array of doubles using a specified floating point precision as an argument to the function. Let's say i have the following code:
void printDoubleArrayPrecision(int length, double *arr, int precision) {
printf("[");
if (length > 0) {
printf("%.2lf", arr[0]);
for (int i = 1; i < length; i++) {
printf(",%.2lf", arr[i]);
}
}
printf("]\n");
}
Is there any way of replacing the 2 in printf(",%.2lf", arr[i]);
with the given argument precision
?