我必须编写输出两个向量的点积的程序。
仅使用 Double 类型组织计算以获得尽可能准确的结果。
输入应如下所示:
Run Code Online (Sandbox Code Playgroud)N - vector length x1, x2,..., xN co-ordinates of vector x (double type) y1, y2,..., yN co-ordinates of vector y (double type)输入样本:
Run Code Online (Sandbox Code Playgroud)4 1.0e20 -1.0e3 0.1 1.0e20 1.0 4.0 -4.0 -1.0以上向量的输出:
Run Code Online (Sandbox Code Playgroud)-4000.4
还有我的代码(我还没有使用 cin 因为起初我想用示例输入编写工作程序):
#include <iostream>
#include <numeric>
#include <vector>
#include <functional>
int main(){
//double N; //length of both vectors , will be used when I will have to input vectors by cin
//std::cin >> N;
//N = 4;
std::vector<double> x{1.0e20, -1.0e3, …Run Code Online (Sandbox Code Playgroud)