求助(急,在线等)

microstoneee 2003-10-02 12:46:24
有一段程序,原来是用x,y坐标输入,然后用另一个function计算距离,现在我想直接读入距离的二维数组,不知如何改?
本人初学,望高手指点,帮助改一下,谢谢!
void input_pbm(int nc,struct node *t,int **ti,FILE *ifp,FILE *ofp)

{ float *x,*y; /*The x,y coordinates */
int i; /*Index.*/
x = (float *)calloc(nc,sizeof(float));
y= (float *) calloc (nc,sizeof(float));
for(i=0;i<nc;++i){ /*input data from the input file, */
fscanf(ifp,"%f",&x[i]);
fscanf(ifp,"%f",&y[i]);
} /*end for*/
convxy(nc,x, y, ti, ofp);
free(x);
free(y);
return;
}/*end input_pbm function*/
void convxy(int nc,float *x, float *y, int **ti, FILE *ofp)
{ int i, j; /* Indices. */
double dx, dy; /* The difference between x and y coordinates.*/
double power(); /* The power function */
for (i=0; i< nc; ++i) /* Computation. */
for (j=i+1; j< nc; ++j) {
dx = x[i] - x[j];
dy = y[i] - y[j];
ti[i][j] = sqrt(dx*dx + dy*dy);
ti[j][i] = ti[i][j];
} /* end for j*/
}/*end for i*/
} /*End convxy*/
...全文
29 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
pentstrstroup 2003-10-05
  • 打赏
  • 举报
回复
试试这样行不行

void convxy(int nc,float *x, float *y, int **ti, FILE *ofp)
{ int i, j; /* Indices. */
double dx, dy; /* The difference between x and y coordinates.*/
double power(); /* The power function */
for (i=0; i< nc; ++i) /* Computation. */
for (j=i+1; j< nc; ++j) {
dx = x[i] - x[j];
dy = y[i] - y[j];
ti[i][j] = sqrt(dx*dx + dy*dy);
ti[j][i] = ti[i][j];
} /* end for j*/
}/*end for i*/
} /*End convxy*/

void input_pbm(int nc,struct node *t,int **ti,FILE *ifp,FILE *ofp)

{ float *x,*y; /*The x,y coordinates */
int i; /*Index.*/
x = (float *)calloc(nc,sizeof(float));
y= (float *) calloc (nc,sizeof(float));
for(i=0;i<nc;++i){ /*input data from the input file, */
fscanf(ifp,"%f",&x[i]);
fscanf(ifp,"%f",&y[i]);
} /*end for*/
convxy(nc,x, y, ti, ofp);
free(x);
free(y);
}/*end input_pbm function*/


69,335

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧