I have to print an array as a 3 by 4 grid How would you go a

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;
}

Solution

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.

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()

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site