Having some fun with multidimensional arrays Consider the pi
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
#include <iostream>
#include <string>
using namespace std;
int main()
{
double data[6][2] = { { 34.9, 22 }, //declaring a 2D array, and initialize it with the data given in the diagram
{ 22.7, 14 },
{ 15.4, 0 },
{ 8.6, 4.4 },
{ 6.3, 9.6 },
{ 12.2, 0 }
};
cout << \"\\t\\tApple money\\tiPhone sales\" << endl; //print header
cout << \"Americas\\t\\t\" << data[0][0] << \"%\\t\" << data[0][1] << \"%\" << endl; //print each row data from the 2D array
cout << \"Europe\\t\\t\\t\" << data[1][0] << \"%\\t\" << data[1][1] << \"%\" << endl;
cout << \"Greater China\\t\\t\" << data[2][0] << \"%\\t\" << data[2][1] << \"%\" << endl;
cout << \"Japan\\t\\t\\t\" << data[3][0] << \"%\\t\" << data[3][1] << \"%\" << endl;
cout << \"Rest of Asia\\t\\t\" << data[4][0] << \"%\\t\" << data[4][1] <<\"%\" << endl;
cout << \"Retail\\t\\t\\t\" << data[5][0] << \"%\\t\" << data[5][1] << \"%\" << endl;
}
----------------------------------------------------------
OUTPUT:
Apple money iPhone sales
Americas 34.9% 22%
Europe 22.7% 14%
Greater China 15.4% 0%
Japan 8.6% 4.4%
Rest of Asia 6.3% 9.6%
Retail 12.2% 0%
