正在加载图片...
#include <math. h> double double z double dist(struct point pl, struct point p2) i double x, y,z,d z=pl. z-p2 z d=sgrt(x*x+y*y+z*z) i struct point pl, p2 printf( Enter pointl scanf (%1f%1f%lf", &pl. x, &pl. y, &pl. z) printf( Enter point2: scanf( %1f%1f%lf, &p2. x, &p2. y, &p2. z) printf("distance: %lf", dist(p1, p2)) 811参考当地的火车时刻表,设计一个程序,对输入的每一个城市名称,能够求出由 你所在的城市有没有直接到达所输入城市的火车,如有,输出铁路距离和火车票价 解:将本地发出列车的时刻表每一到站的信息定义为结构,给出城市名称查找表中位置的 操作定义为函数。参考程序如下: include <stdio. h> #definen 50 typedef struct city I char name [20] double dist cIt void input(city cp, int n) printf( Enter city message( name dist price): \n")#include <math.h> struct point { double x; double y; double z; }; double dist(struct point p1, struct point p2) { double x,y,z,d; x=p1.x-p2.x; y=p1.y-p2.y; z=p1.z-p2.z; d=sqrt(x*x+y*y+z*z); return d; } main() { struct point p1,p2; printf("Enter point1:"); scanf("%lf%lf%lf",&p1.x,&p1.y,&p1.z); printf("Enter point2:"); scanf("%lf%lf%lf",&p2.x,&p2.y,&p2.z); printf("distance : %lf",dist(p1,p2)); } 8.11 参考当地的火车时刻表,设计一个程序,对输入的每一个城市名称,能够求出由 你所在的城市有没有直接到达所输入城市的火车,如有,输出铁路距离和火车票价。 解:将本地发出列车的时刻表每一到站的信息定义为结构,给出城市名称查找表中位置的 操作定义为函数。参考程序如下: #include <stdio.h> #define N 50 typedef struct city { char name[20]; double dist; double price; } city; void input(city *cp,int n) { int i,k; double a,b; printf("Enter city message( name dist price):\n"); for (i=0;i<n;i++)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有