Пишу курсовую по С++ - суть такова есть n(1<n<=100) точек в 3-мерном пространстве с координатами (Xi, Yi, Zi) (i=1,n); Нужно узнать порядковые номера двух точек, которые имеют наибольшее расстояние между собой. Вот что я написал:| Код | #include <iostream> #include <math.h> #include <conio.h>
int load (); void max(int n);
struct point { int x,y,z; };
point mas[100]; double lines[100];
int main () { char a; int n; do{ system("cls"); printf("1 - Load points from file.\n"); printf("2 - Two points with maximal distance.\n"); printf("ESC - Exit.\n");
a=getch(); switch (a){ case '1': n=load(); break; case '2': max(n); break; case 27: return 0; } }while(1); return 0; }
int load () { int i; FILE *f;
if ((f=fopen("points.txt","rt"))==0) { system("cls"); printf("Error. File not found.\nPress any key..."); getch(); return 0; }
i=0;
while (!(feof(f))) { fscanf(f,"%d %d %d\n",mas[i].x,mas[i].y,mas[i].z); i++; } printf("%d points loaded...",i); getch(); return i; }
void max (int n) { int i,j; for (j=0;j<i;j++) { lines[j]=sqrt(pow((double)(mas[j].x-mas[j+1].x),2)+pow((double)(mas[j].y-mas[j+1].y),2)+pow((double)(mas[j].z-mas[j+1].z),2)); } lines[i]=sqrt(pow((double)(mas[i-1].x-mas[0].x),2)+pow((double)(mas[i-1].y-mas[0].y),2)+pow((double)(mas[i-1].z-mas[0].z),2)); system("cls"); printf("max %d points"); return; }
|
собирается нормально но после запуска и выбора в меню загрузка точек, получаю крит |