Example: Please add a function that averages the one-dimensional array A [N] and rounds the result to two decimal places.

For example, when a [10] = {23.1, 12.3, 5.3, 56.4, 10.0, 13.7, 24.5, 42,1.2, 9.9}, the output is: business = 19.840000. Do not change anything in main or the other functions. Only fill in the necessary expressions or statements along the lines of fun.

The code is as follows:

#include<stdio.h>
#include<conio.h>
double fun(double a[10])
{
	int i;
	long temp;
	double average=0.0;
	double sum=0.0;
	for(i=0; i<10; i++) sum+=a[i]; average=sum/10;
	average=average*1000;
	temp=(average+5) /10;
	average=(double)temp/100;
	return average;
}
main()
{
	double average,a[10] = {23.1.12.3.5.3.56.4.10.0.13.7.24.5.42.1.2.9.9};
	int i;
	printf("\nThe data:\n");
	for(i=0; i<10; i++)printf("% 6.1 f",a[i]);
	printf("\n\n");
	average=fun(a);
	printf("The average=%f\n\n",average);
}
Copy the code

The output running window is as follows:



Other exercises this week

C programming column

In the following program, fun replaces all substrings referred to by temp1 in the string referred to by STR with substrings referred to by temp2, and places the resulting string in the array referred to by result.

② Please add a function to find the average value of the one-dimensional array A [N], and round the result to keep two decimal places.

③ Please add the main function, the function is: calculate the average score of four students in each subject.

In the following given program, the function fun swaps two integers.

This function outputs an N×N matrix, requiring that the non-diagonal elements be assigned 1 and the diagonal elements be assigned 0.

> 19 weeks 6 C language programming function is the function of fun in the following a given procedure: from low to start them on a long integer variables x in the coded number, in turn, constitute a new number in y.

Fun returns the youngest child in the student array and outputs the youngest child in main.

In the following program, fun replaces the last occurrence of s1 in the string referred to by S with s2, and places the new string referred to by STR in the data.

The harder you work, the luckier you get! Come on, Aoli!!