C 语言实例 - 计算标准偏差

C 语言教程 · 2019-02-21 07:11:50

计算标准偏差。

实例

#include <stdio.h> #include <math.h> float calculateSD(float data[]); int main() { int i; float data[10]; printf("输入10个元素: "); for(i=0; i < 10; ++i) scanf("%f", &data[i]); printf("\n标准偏差 = %.6f", calculateSD(data)); return 0; } float calculateSD(float data[]) { float sum = 0.0, mean, standardDeviation = 0.0; int i; for(i=0; i<10; ++i) { sum += data[i]; } mean = sum/10; for(i=0; i<10; ++i) standardDeviation += pow(data[i] - mean, 2); return sqrt(standardDeviation/10); }

输出结果为:

输入10个元素: 1
2
3
4
5
6
7
8
9
10

标准偏差 = 2.872281

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

The Definitive Guide to HTML5 WebSocket

The Definitive Guide to HTML5 WebSocket

Vanessa Wang、Frank Salim、Peter Moskovits / Apress / 2013-3 / USD 26.30

The browser is, hands down, the most popular and ubiquitous deployment platform available to us today: virtually every computer, smartphone, tablet, and just about every other form factor imaginable c......一起来看看 《The Definitive Guide to HTML5 WebSocket》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具