average and standard deviation-平均数和标准差
2014-08-31 16:11
323 查看
average and standard deviation-平均数和标准差(4个数),允许重复计算:
//average and standard deviation-平均数和标准差 #include<iostream> #include<cmath> using namespace std; double average(double s1,double s2,double s3,double s4); double standard_deviation(double s1,double s2,double s3,double s4,double average); int main() { double s1,s2,s3,s4; double ave,sta_dev; char ans; do{ cout<<"Please input four numbers:\n"; cin>>s1>>s2>>s3>>s4; ave = average(s1,s2,s3,s4); sta_dev = standard_deviation(s1,s2,s3,s4,ave); cout<<"The average is "<<ave<<endl; cout<<"The standard deviation is "<<sta_dev<<endl; cout<<"Do you want again?"; cin>>ans; }while('y' == ans || 'Y' == ans); return 0; } double average(double s1,double s2,double s3,double s4) { return (s1+s2+s3+s4)/4; } double standard_deviation(double s1,double s2,double s3,double s4,double average) { return sqrt((pow((s1 - average),2) + pow((s2 - average),2) + pow((s3 - average),2) + pow((s4 - average),2))/4); }结果:
Please input four numbers: 1 2 3 4 The average is 2.5 The standard deviation is 1.11803 Do you want again?y Please input four numbers: 12.3 13.4 10.5 9.0 The average is 11.3 The standard deviation is 1.68375 Do you want again?y Please input four numbers: 5 5 5 5 The average is 5 The standard deviation is 0 Do you want again?
相关文章推荐
- Mean and Standard Deviation-从文件中读取数据计算其平均数和标准差
- Mean, Median, Mode, Range, and Standard Deviation
- average variance standardDeviation
- Mathematics | Mean, Variance and Standard Deviation
- Standard Deviation And Correlation
- Precision、Recall and Mean Average Precision(MAP)
- Java Data Mining: Strategy, Standard, and Practice: A Practical Guide for architecture, design, and
- JPEG2000 Standard for Image Compression: Concepts, Algorithms and VLSI Architectures
- Expecting "jsp:param" standard action with "name" and "value" attributes错误
- Delphi文件学习 Standard Routines and I/O
- C Standard Library: 10 Date and Time Functions: <time.h>
- 033-Unit 5 Standard I/O and Pipes
- UVaLive LA 4726 UVa 1451 - Average (子序列最大平均数 数形结合 斜率优化 单调队列)
- Android ADK with a standard Arduino Uno and USB Host Shield
- The C++ Standard Library : A Tutoral and Reference 读书笔记之auto_ptr
- C++ standard for managed and unmanaged code
- Expecting "jsp:param" standard action with "name" and "value" attributes错误
- Oracle Database 11g Release 2 Standard Edition and Enterprise Edition Software Downloads
- standard fga and fga
- Accessing Standard and Dynamic MBeans via the RMI Connector