Doing Physics Experiment
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1035 Accepted Submission(s): 558
Problem Description
As far as Samuel is concerned,physics is very dull and doing the physics experiment is a waste of time. So Samuel only got a passing score in the experiment this semester. Dealing with the figures that get from the experiment requires a lot of energy and time,and it is not valuable to do it by press the calculator to get answer. So Samuel and his roommates often make up a program to work it out. Can you help Samuel make a program?
The problem is not hard. You only need to figure out the average M of n number(double type x1,x2,x3...xn) (the precision set as 10).
The problem is not hard. You only need to figure out the average M of n number(double type x1,x2,x3...xn) (the precision set as 10).
Input
test cases t,each of a test case contains a number n(an integer) and n figures(double type).
Output
Output the average M by “The average M = m.”here m is a number.
Sample Input
1 3 1.0 1.2 1.1
Sample Output
The average M = 1.1000000000.
AC代码:
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> using namespace std; int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); double sum=0; for(int i=0;i<n;i++) { double a; scanf("%lf",&a); sum+=a; } printf("The average M = %.10lf.\n",sum/n); } return 0; }