就用 C 语言把这个公式写出来不就行了?
a^2 写成 a*a 之类的。
#include <stdio.h> #include <math.h> int main() { double a, b, c, h1, h2, k1, k2, l1, l2; double cosine; printf("input arguments by this order:\n" " a, b, c, h1, h2, k1, k2, l1, l2\n"); if (scanf("%lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf", &a, &b, &c, &h1, &h2, &k1, &k2, &l1, &l2) != 9) { puts("inputs invalid!"); return 1; } a *= a; b *= b; c *= c; cosine = (h1*h2/a + k1*k2/b + l1*l2/c) / sqrt( (h1*h1/a + k1*k1/b + l1*l1/c) * (h2*h2/a + k2*k2/b + l2*l2/c) ); printf("cosine = %lf\n", cosine); return 0; }