#include <stdio.h>
float media( int n, float * v) {
float s = 0 ;
for ( int i = 0 ; i < n; i++ ) {
s += v[ i] ;
}
return s / n;
}
float variancia( int n, float * v, float m) {
float s = 0 ;
for ( int i = 0 ; i < n; i++ ) {
s += ( v[ i] - m) * ( v[ i] - m) ;
}
return s / n;
}
int main( ) {
float v[ 10 ] ;
for ( int i = 0 ; i < 10 ; i++ ) {
printf ( "Digite um numero:\n " ) ; }
float med = media( 10 , v) ;
float var = variancia( 10 , v, med) ;
printf ( "Media = %f Variancia = %f \n " , med
, var
) ; }
//https://pt.stackoverflow.com/q/204372/101
I2luY2x1ZGUgPHN0ZGlvLmg+CgpmbG9hdCBtZWRpYShpbnQgbiwgZmxvYXQqIHYpIHsKCWZsb2F0IHMgPSAwOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKCQlzICs9IHZbaV07Cgl9CglyZXR1cm4gcyAvIG47Cn0KCmZsb2F0IHZhcmlhbmNpYShpbnQgbiwgZmxvYXQqIHYsIGZsb2F0IG0pIHsKCWZsb2F0IHMgPSAwOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKCQlzICs9ICh2W2ldIC0gbSkgKiAodltpXSAtIG0pOwoJfQoJcmV0dXJuIHMgLyBuOwp9CgppbnQgbWFpbigpIHsKCWZsb2F0IHZbMTBdOwoJZm9yIChpbnQgaSA9IDA7IGkgPCAxMDsgaSsrKSB7CgkJcHJpbnRmKCJEaWdpdGUgdW0gbnVtZXJvOlxuIik7CgkJc2NhbmYoIiVmIiwgJnZbaV0pOwoJfQoJZmxvYXQgbWVkID0gbWVkaWEoMTAsIHYpOwoJZmxvYXQgdmFyID0gdmFyaWFuY2lhKDEwLCB2LCBtZWQpOwoJcHJpbnRmKCJNZWRpYSA9ICVmIFZhcmlhbmNpYSA9ICVmIFxuIiwgbWVkLCB2YXIpOwp9CgovL2h0dHBzOi8vcHQuc3RhY2tvdmVyZmxvdy5jb20vcS8yMDQzNzIvMTAx