Last active
December 27, 2016 12:02
-
-
Save Rogeman/36ee07cb3742d0b81b6018b393836d9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
double distancia(int x1,int y1,int x2,int y2){ | |
double distx=x2-x1; | |
double disty=y2-y1; | |
double distanciaalcuadrado=abs(pow(distx,2)+pow(disty,2)); | |
double distancia=sqrt(distanciaalcuadrado); | |
return distancia; | |
} | |
void mediaPuntos(int intervalos){ | |
double suma=0; | |
int contador=0; | |
double media=0.0; | |
double distancias=0.0; | |
int x1=1; | |
int x2=1; | |
int y1=1; | |
int y2=1; | |
double medianor=0; | |
for(x1=1;x1<=intervalos;x1++){ | |
for(y1=1;y1<=intervalos;y1++){ | |
for(x2=1;x2<=intervalos;x2++){ | |
for(y2=1;y2<=intervalos;y2++){ | |
contador++; | |
distancias=distancia(x1,y1,x2,y2); | |
suma=suma+distancias; | |
media=suma/contador; | |
medianor=media/intervalos; | |
//printf("%d:(%d,%d)-(%d,%d)=%f [%f/%d]=%f\n",contador,x1,y1,x2,y2,distancias,media,intervalos,medianor); | |
} | |
} | |
} | |
} | |
printf("%d:%d [%f/%d]=%f\n",intervalos,contador,media,intervalos,medianor); | |
} | |
void main(void){ | |
printf("sumando distancias\n"); | |
int intervalos=10; | |
int intervalosmax=100000; | |
for(;intervalos<=intervalosmax;intervalos++){ | |
mediaPuntos(intervalos); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment