Algorithm that generates orthogonal vectors: C++ implementation
Welcome to C++.

It seems that you are more or less trying to write C code rather than C++ though. Lets have a look at what you can improve:


Never do using namespace std; It is a terrible practise that gets you into trouble really fast. std:: is not that hard to type so get in the habit early.
If you have compile time constants use them via constexpr
Your dot_product function is already implemented in the standard library. It is called inner_product. So the following code can be replaced


float dot_product(float *vector1, float vector2[],int dimension){
    float sum = 0;
    for (int i = 0; i &lt; dimension; i++){
        sum += (vector1[i])*(vector2[i]);
    }
    return sum;
}



by the following code

std::inner_product(a.cbegin(), a.cend(), b.cbegin(), float(0.0));

Similarly there is a generate function that fills a vector with a generator. Note that C++ has a variety of good random number generators (rand() is not one of them) in the &lt;random&gt; header. I don't know why you use integers for the float vectors but you can adapt that easily.

EDIT: Incorporated problems found by @L.F.

#include &lt;algorithm&gt;
#include &lt;random&gt;

class randomStreamUniformInt {
public:
    explicit randomStreamUniformInt(int lower_bound, int upper_bound)
    : mt(std::random_device{}()), uniform_dist(lower_bound, upper_bound) {}
    explicit randomStreamUniformInt(int lower_bound, int upper_bound, double seed)
    : mt(seed), uniform_dist(lower_bound, upper_bound) {}

    int operator() () { return uniform_dist(mt); }
private:
    std::mt19937_64                     mt;
    std::uniform_int_distribution&lt;&gt;     uniform_dist;
};

static randomStreamUniformInt rng(-MAXRANGE, MAXRANGE); 

std::vector&lt;float&gt; generate random(const std::size_t numElements) {
    std::vector&lt;float&gt; res(numElements);
    std::generate(res.begin(), res.end(), rng);
    return res;
}


It would be even better to pass the random number generator as an argument rather than a global variable. I leave that as an exercise.
You should use standard facilities for arrays such as std::vector or std::array depending on whether you know the size at compile time. So the following code:


float arbitrary_vector[dimension], orthogonal[dimension]



Should be better written as

std::vector&lt;float&gt; arbitrary_vector = generate_random(dimension);


Note that it is always better to put each declaration into a single line.
Your method generate_orthogonal can be improved accordingly.

std::vector&lt;float&gt; generate_orthogonal(const std::vector&lt;float&gt;&amp; a) {
    // get some random data
    std::vector&lt;float&gt; b = generate_random(a.size());

    // find the last non zero entry in a
    // We have to turn the reverse iterator into an iterator via std::prev(rit.base())
    auto IsZero = [] (const float f) -&gt; bool { return f == float(0.0);};
    auto end = std::prev(std::find_if_not(a.crbegin(), a.crend(), IsZero).base());

    // determine the dot product up to end
    float dot_product = std::inner_product(a.cbegin(), end, b.cbegin(), float(0.0));

    // set the value of b so that the inner product is zero
    b[std::distance(a.cbegin(), end)] = - dot_product / (*end);

    return b;
}



So put together it would look something like this:

#include &lt;algorithm&gt;
#include &lt;random&gt;
#include &lt;vector&gt;

constexpr int MAXRANGE = 1000;

class randomStreamUniformInt {
public:
    explicit randomStreamUniformInt(int lower_bound, int upper_bound)
    : mt(std::random_device{}()), uniform_dist(lower_bound, upper_bound) {}
    explicit randomStreamUniformInt(int lower_bound, int upper_bound, double seed)
    : mt(seed), uniform_dist(lower_bound, upper_bound) {}

    int operator() () { return uniform_dist(mt); }
private:
    std::mt19937_64                     mt;
    std::uniform_int_distribution&lt;&gt;     uniform_dist;
};

static randomStreamUniformInt rng(-MAXRANGE, MAXRANGE); 

std::vector&lt;float&gt; generate random(const std::size_t numElements) {
    std::vector&lt;float&gt; res(numElements);
    std::generate(res.begin(), res.end(), rng);
    return res;
}

std::vector&lt;float&gt; generate_orthogonal(const std::vector&lt;float&gt;&amp; a) {
    // get some random data
    std::vector&lt;float&gt; b = generate_random(a.size());

    // find the last non zero entry in a
    // We have to turn the reverse iterator into an iterator via std::prev(rit.base())
    auto IsZero = [] (const float f) -&gt; bool { return f == float(0.0);};
    auto end = std::prev(std::find_if_not(a.crbegin(), a.crend(), IsZero).base());

    // determine the dot product up to end
    float dot_product = std::inner_product(a.cbegin(), end, b.cbegin(), float(0.0));

    // set the value of b so that the inner product is zero
    b[std::distance(a.cbegin(), end)] = - dot_product / (*end);

    return b;
}

int main() {
    std::size_t dimension = 20;

    std::vector&lt;float&gt; a = generate_random(dimension);
    std::vector&lt;float&gt; b = generate_orthogonal(a);
}