A voir également:
- Distance sur c
- Bloquer un téléphone à distance avec imei - Forum Android
- Éteindre pc à distance - Guide
- Comment detruire un telephone a distance - Forum Mobile
- Prendre le controle d'un pc a distance sans autorisation - Forum Programmation
- Application distance parcourue à pied gratuite - Télécharger - Sport
4 réponses
Hadra38
Messages postés
100
Date d'inscription
mercredi 9 avril 2008
Statut
Membre
Dernière intervention
3 mars 2011
11
10 mai 2010 à 11:13
10 mai 2010 à 11:13
je propose :
qu'en penses tu ?
#include <math.h>
typedef struct Point Point;
struct Point
{
int x;
int y;
};
Point tableau_de_point[100];
int Matrice_Distance[100][100];
// initialisation du tableau
for(int i=0; i < 100; i++) {
tableau_de_point[i].x = ?? ;
tableau_de_point[i].y = ?? ;
}
// -----------
// creation de la matrice de distance
for(int i=0; i < 100; i++) {
for(int j=0; j<100 ; j++) {
Matrice_Distance[i][j] = sqrt( (tableau_de_point[i].x - tableau_de_point[j].x) * (tableau_de_point[i].x - tableau_de_point[j].x) + (tableau_de_point[i].y - tableau_de_point[j].y) * (tableau_de_point[i].y - tableau_de_point[j].y) );
}
}
// -----------
qu'en penses tu ?
Char Snipeur
Messages postés
9688
Date d'inscription
vendredi 23 avril 2004
Statut
Contributeur
Dernière intervention
2 octobre 2020
1 328
10 mai 2010 à 11:17
10 mai 2010 à 11:17
optimisation:
for(int i=0; i < 100; i++) {
for(int j=0; j<100 ; j++) {
if(j>i)Matrice_Distance[i][j] = sqrt( (tableau_de_point[i].x - tableau_de_point[j].x) * (tableau_de_point[i].x - tableau_de_point[j].x) + (tableau_de_point[i].y - tableau_de_point[j].y) * (tableau_de_point[i].y - tableau_de_point[j].y) );
else if(i==j)Matrice_Distance[i][j]=0;
else Matrice_Distance[i][j]=Matrice_Distance[j][i];
}
Hadra38
Messages postés
100
Date d'inscription
mercredi 9 avril 2008
Statut
Membre
Dernière intervention
3 mars 2011
11
10 mai 2010 à 11:34
10 mai 2010 à 11:34
bien vu
10 mai 2010 à 11:17
la fonction sqrt() de Math.h renvoie un "double" donc corrige :
"int Matrice_Distance[100][100];" en "double Matrice_Distance[100][100];"