Questions sum averaging algorithm training
Resource limitation
time limit: 1.0s memory limit: 256.0MB
Problem Description
input from the keyboard 10 float, and they determine the average value and, using the function requires
input format
format of the input test data must be satisfied.
110 (a row vector 10) of
the output format
required to meet the user's output format.
21 (a matrix of 2 rows)
sample input
an input example to meet the requirements of the subject.
Example:
1.2 2.2 3.2 4.2 5.2 6.2 7.2 8.2 10.2 9.2
Sample output
with an output corresponding to the sample input above.
Example:
57
5.7
size of the data and the agreed
input data range of each number.
Example: 0 <n, m <100 , 0 < = the number of each matrix <= 1000.
Ideas: the definition of a variable number of input and adding the digital output is summed and then divided by the number of digital output is the average value.
code show as below:
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
double sum=0,j;
for(int i=0;i<10;i++){
cin>>j;
sum+=j;
}
cout<<sum<<endl;
cout<<sum/10;
}