Average of subarrays of length k in C++ I took a crack at solving the problem of finding the averages of all subarrays of length k. Here is what I came up with. I would greatly appreciate your feedback on  my code. 

#include &lt;algorithm&gt;
#include &lt;iostream&gt;
#include &lt;numeric&gt;
#include &lt;vector&gt;

using namespace std;

vector&lt;double&gt; findSuseqAverages(size_t k, const vector&lt;int&gt;&amp; nums) {

    vector&lt;double&gt; res (nums.size() - k + 1);
    auto left_it = nums.begin();
    auto right_it = next(left_it, k);
    double curr_sum = accumulate(left_it, right_it, 0);

    size_t res_index = 0;
    res.at(res_index) = curr_sum / k;

    while (right_it != nums.end()) { 
        curr_sum += *right_it - *left_it;
        res.at(++res_index) = curr_sum / k;        
        ++right_it;
        ++left_it;         
    }

    return res;
}  

int main() {
    vector&lt;int&gt; nums {-1, 0, 1};
    size_t k = 2;
    vector&lt;double&gt; averages = findSuseqAverages(k, nums);

    for (const auto&amp; a: averages) cout &lt;&lt; a &lt;&lt; " ";
    cout &lt;&lt; "\n\n";
}
Generally the code is well written, there are only a few items that need commenting on.
Avoid Using Namespace std
If you are coding professionally you probably should get out of the habit of using the using namespace std; statement. The code will more clearly define where cout and other identifiers are coming from (std::cin, std::cout). As you start using namespaces in your code it is better to identify where each function comes from because there may be function name collisions from different namespaces. The identifier cout you may override within your own classes. This stack overflow question discusses this in more detail.
Use Braces Around Single Statements in Program Flow
Primarily for maintenance reasons it is a good habit to create code blocks within if statements, else clauses and within loops. Many bugs have been created during maintenance when one or more statements was added to an if statement or a loop.
From this code:
    for (const auto&amp; a: averages) cout &lt;&lt; a &lt;&lt; &quot; &quot;;

Would be better as
    for (const auto&amp; a: averages) {
        std::cout &lt;&lt; a &lt;&lt; &quot; &quot;;
    }

Then if someone needs to add a statement to the for loop at some point it is quite simple.
This Code Could Be Simplified
    vector&lt;double&gt; res (nums.size() - k + 1);
        ...

    size_t res_index = 0;
    res.at(res_index) = curr_sum / k;

    while (right_it != nums.end()) { 
        ...
        res.at(++res_index) = curr_sum / k;      
        ...  
    }

It's not clear why it was necessary to initialize the res vector to the proper size in the previous code. Since vectors are variable sized they don't need to be initialized with a size.
    std::vector&lt;double&gt; res;
        ...

    res.push_back(curr_sum / k);

    while (right_it != nums.end()) { 
        ...
        res.push_back(curr_sum / k);      
        ...  
    }

removes one variable and achieves the same result.