以下是C++代码实现:

#include <iostream>
#include <cmath>
using namespace std;

double VectorLength(double L[]) {
    double length = sqrt(L[0]*L[0] + L[1]*L[1] + L[2]*L[2]);
    return length;
}

int main() {
    double v[3] = {3, 4, 5};
    double length = VectorLength(v);
    cout << "The length of the vector is " << length << endl;
    return 0;
}

输出结果:

The length of the vector is 7.07107
完成 double VectorLengthL函数L是double类型的数组长度为3代表三维向量。函数功能为计算该向量的长度并返回结果

原文地址: https://www.cveoy.top/t/topic/FyQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录