|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<math.h>
int main()
{
float GPS1[3],GPS2[3];
int i=0,j=0;
float d;
printf("Please input the first coordinate of the point:\n");
for(i;i<3;i++)
{
scanf("%f",GPS1[i]);
}
printf("Please input the second coordinate of the point");
for(j;j<3;j++)//从这开始代码就没有继续运行下去了,为什么?如何改进?
{
printf("--------");
scanf("%f",GPS2[j]);
}
d=sqrt((GPS1[0]-GPS2[0])*(GPS1[0]-GPS2[0])
+(GPS1[1]-GPS2[1])*(GPS1[1]-GPS1[1])
+(GPS1[2]-GPS2[2])*(GPS1[2]-GPS2[2]));
printf("The distance of the two points is %f",d);
return 0;
}
scanf() 读取数值给出的参数必须是变量地址,不可以直接使用变量本身。
- #include<stdio.h>
- #include<math.h>
- int main(void)
- {
- float d , e , GPS[2][3] ;
- int i , j ;
- for(i = 0 ; i < 2 ; i ++) {
- printf("Please input the No. %d coordinate of the point:\n" , i + 1) ;
- for(j = 0 ; j < 3 ; j ++) scanf("%f" , & GPS[i][j]) ;
- }
- for(e = 0.0 , i = 0 ; i < 3 ; i ++) e += (GPS[1][i] - GPS[0][i]) * (GPS[1][i] - GPS[0][i]) ;
- d = sqrt(e) ;
- printf("The distance of the two points is : %.6f\n" , d) ;
- }
复制代码
vc6.0 环境编译、运行实况
- D:\0002.Exercise\C>cl x.c
- Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
- Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
- x.c
- Microsoft (R) Incremental Linker Version 6.00.8447
- Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
- /out:x.exe
- x.obj
- D:\0002.Exercise\C>x
- Please input the No. 1 coordinate of the point:
- 0 0 0
- Please input the No. 2 coordinate of the point:
- 10 10 10
- The distance of the two points is : 17.320508
- D:\0002.Exercise\C>
复制代码
|
|