Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have to print an array as a 3 by 4 grid. How would you go about doing that? Th

ID: 3783238 • Letter: I

Question

I have to print an array as a 3 by 4 grid. How would you go about doing that? This is the code so far.

#include<iostream>
using namespace std;

int main()

{

   double volts[8];
   volts[0] = 11.13;
   volts[1] = 14.22;
   volts[2] = 15.39;
   volts[3] = 16.24;
   volts[4] = 16.29;
   volts[5] = 18.98;
   volts[6] = 19.54;
   volts[7] = 23.75;

                                                      
                                                                          
   int i;

   for (i = 0; i < 8; i++)
   {
       cout << volts[i] << endl;
   }
   system("pause");
   return 0;
}

Explanation / Answer

In order to print an array as 3 by 4 grid. You can follow the below code:

int i,j;

for(i=0;i<3;i++)

{

for(j=0;j<4;j++)

{

cout<<volts[i][j]<<" ";

}

cout<<endl;

}//end of outer for loop

Hope it helps.