Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
random()%N stddev
//clang 3.8.0 #include <stdio.h> #include <stdlib.h> #include <math.h> #define N 100 int main(void) { int highest, lowest, mean = 0; double var = 0.0, stddev; // create an array 0-99 and zero-fill int x[N] = {0}; // loop and fill 200K times for (int i=200000;i--;) x[random()%N]++; // analyze // calc mean for (int i=N;i--;) mean+=x[i]; mean /= N; lowest=highest=mean; for (int i=N;i--;) { if (x[i] < lowest) lowest = x[i]; if (x[i] > highest) highest = x[i]; var += pow((x[i] - mean), 2.0); printf("%i %i\n", i, x[i]); } var /= N; stddev = sqrt(var); printf("\nHighest: %i" "\nLowest: %i" "\nMean: %i" "\nVariance:%lf" "\nStddev: %lf", highest, lowest, mean, var, stddev); return 0; }
run
|
edit
|
history
|
help
0
Ducktype
Ordena de menor a mayor 3 numeros
Herout (67) - 13
Condiciones: Puntos cuadrantes
Punteros: creación espacio para un int
Roots of a Quadratic Equation
lab7
Triples bucles anidados
13 12 2014 20:25
Code