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>
|