c++ array. Looking for better solution So i got an task from school.
Which ask's me to write a program tad creates an 2d array with 11 rows and 5 columns.
In which the first column starts with 2.0 and increments by 0.1 all the way up to 3.0.
Then in next column it should be devided by 1 so if x is 2.0 then 1 / x and goes trough all 11 rows.
then in next column it has to multiply by 2 so x^2 and repeat in every column up to x^4.
So so far i got it to do what i need , but i know there should be a better way to achieve this. as if there would be a task to go up to x^50 for example i imagine it would be pain to do with my way. as its hardcoded.
So here is my code:
#include&lt;iostream&gt;
#include&lt;iomanip&gt;
#include&lt;array&gt;

using namespace std;

int main()
{
 const int rows = 11;
 const int columns = 5;
 double x = 2.0;


 array&lt;array&lt;double, columns&gt;,rows&gt; A{};
 cout &lt;&lt; setprecision(2);
 cout &lt;&lt; fixed;
 cout &lt;&lt; setw(2) &lt;&lt;&quot;x&quot; &lt;&lt; setw(10) &lt;&lt; &quot;1/x&quot; &lt;&lt; setw(7) &lt;&lt; &quot;x^2&quot; &lt;&lt; setw(7) &lt;&lt; &quot;x^3&quot; &lt;&lt; setw(8)&lt;&lt; &quot;x^4\n&quot;;
 cout &lt;&lt; &quot;------ ------ ------ ------ ------\n&quot;;
 A[0][0] = x;
 for(int i = 0; i &lt; A.size(); i++)
 {
     A[i+1][0] = A[i][0] + 0.1;
     A[i][1] = 1 / A[i][0];
     A[i][2] = A[i][0] * A[i][0] * A[i][0];
     A[i][3] = A[i][0] * A[i][0] * A[i][0]* A[i][0];
     A[i][4] = A[i][0] * A[i][0] * A[i][0]* A[i][0] * A[i][0] ;
     for(int j = 0; j &lt; A[0].size(); j++)
     {
         cout &lt;&lt; A[i][j] &lt;&lt; setw(4)  &lt;&lt; &quot; &quot;;
     }
     cout &lt;&lt; endl;
 }

 return 0;
 }

and here is how it's supposed to look:

Looking for suggestions or tips. I am strugling here.
And sorry for my english it's not my native.
You're almost there, you just need to use std::pow() to raise a value to an arbitrary power, and add another for-loop to handle the repetetive work of filling in all the remaining columns:
for(int i = 0; i &lt; A.size(); i++)
{
     A[i][0] = 2.0 + 0.1 * i;
     A[i][1] = 1 / A[i][0];

     for(int j = 2; j &lt; A[i].size(); j++)
     {
         A[i][j] = std::pow(A[i][0], j);
     }
     ...
}