In: Computer Science
In C language:
Write a function which can receive a float array, an integer number(number of elements) as input arguments and print all the elements in the array with 2 decimal precision.
C code:
#include <stdio.h>
//initializing print function
void print(float numbers[],int n){
//loop to print all numbers
for(int i=0;i<n;i++)
//printing each number with 2 decimal
point
printf("%.2f\n",numbers[i]);
}
int main()
{
//initializing a sample numbers array
float numbers[]={1.234,2.3333,3.4444};
//calling print function
print(numbers,3);
return 0;
}
Screenshot:
Output: