小编Gol*_*nRC的帖子

2 个向量 C++ 的点积

我必须编写输出两个向量的点积的程序。

仅使用 Double 类型组织计算以获得尽可能准确的结果。

输入应如下所示:

   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 
Run Code Online (Sandbox Code Playgroud)

还有我的代码(我还没有使用 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)

c++ floating-point

6
推荐指数
1
解决办法
1380
查看次数

标签 统计

c++ ×1

floating-point ×1