How to represent a mathematical vector in C++

1 Answer

0 votes
// How do you represent a mathematical vector in C++? 
// Use std::vector<double> for dynamic size or std::array<double, N> for fixed size.

#include <iostream>
#include <vector>
#include <array>

int main() {
    std::vector<double> v = {1.0, 2.0, 3.0};
    std::array<double, 3> u = {4.0, 5.0, 6.0};

    std::cout << "v[1] = " << v[0] << "\n";
    std::cout << "u[2] = " << u[0] << "\n\n";
    
    std::cout << "v[1] = " << v[1] << "\n";
    std::cout << "u[2] = " << u[2] << "\n";
}



/*
run:

v[1] = 1
u[2] = 4

v[1] = 2
u[2] = 6

*/

 



answered 6 hours ago by avibootz
edited 3 hours ago by avibootz
...