#include <stdio.h>struct complex{int real;int imag; };//结构体定义:分为实部和虚部struct complex multiply(struct complex x, struct complex y); //函数声明 int main() {struct complex product, x, y;scanf("%d%d%d%d", &x.real, &x.imag, &y.real, &y.imag);//输入俩实部和虚部product = multiply(x, y);//使用函数返回复数计算的结果printf("(%d+%di) * (%d+%di) = %d + %di\n", x.real, x.imag, y.real, y.imag, product.real, product.imag);return 0; }struct complex multiply(struct complex x, struct complex y){struct complex res;res.real=x.real*y.real-x.imag*y.imag;res.imag=x.real*y.imag+x.imag*y.real;return res; }
#include <stdio.h> #include <math.h>struct point {double x, y, z; };void read_point(struct point *p); double distance(struct point a, struct point b);int main(void) {struct point p1, p2;read_point(&p1);read_point(&p2);printf("%f\n", distance(p1, p2));return 0; }void read_point(struct point *p) {scanf("%lf %lf %lf", &p->x, &p->y, &p->z); }// 计算并返回平面上两点 a 和 b 之间的欧氏距离 double distance(struct point a, struct point b){double res;res=pow((a.x-b.x),2)+pow((a.y-b.y),2)+pow((a.z-b.z),2);res=sqrt(res);return res; }