Question
manual trace the following code int numbers [5][3] = { {1, 2, 5} , {2, 4, 3}, {1, 9, 8} , {2, 6, 5}, {7,
manual trace the following code
int numbers [5][3] = { {1, 2, 5} , {2, 4, 3}, {1, 9, 8} , {2, 6, 5}, {7, 4, 2}};
int counts [9] = {0};
int digit = 1; //keeps track of numbers from 1 through 9
while (digit <= 9)
{
for (int row = 0; row < 5; row = row + 1)
for (int col = 0; col < 3; col = col + 1)
//count the number of times the digit appears in the numbers array
if (numbers[row] [col} == digit)
counts[digit - 1] = counts[digit - 1] + 1;
//end if
//end for
//end for
digit = digit + 1; //look for next digit
}//end while
//display counts
for (int x = 0; x < 9; x = x + 1)
cout << "The number " << x + 1 << " appears "
<< counts [x] << " time(s) ." << endl;
// end for
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started