C++ Programming: Two Dimension Random Fill, Sort, Print, and Average Develop a t
ID: 3821832 • Letter: C
Question
C++ Programming:
Two Dimension Random Fill, Sort, Print, and Average
Develop a two dimensional array of, at least, ten rows and ten columns and fill it using the random number generator. Print out the contents of the array in a matching number of rows and columns. Sort the array for smallest to largest. Print out the contents of the array in a matching number of rows and columns. Add all of the elements of the array and output the total and the average along with appropriate information to the user.
Explanation / Answer
All the functions for the particular performance of an array is give as below
1. For filling Random Values In 2D Array
#include "utils.h"
void f_tbl(int tbl[size_RC][size_RC]) {
for(int a = 0; a < size_RC; a++) {
for(int b = 0; b < size_RC; b++)
{
tbl[a][b] = rand() % MAX_VALUE;
cout << tbl[a][b] << " ";
}
}
}
2. For Picking Up the Largest Value in Array
void lg_RC(int tbl[size_RC][size_RC], int& largestRow,
int& largestCol) {
largestRow = 0;
largestCol = 0;
for ( int a = 0; a < size_RC; a++) {
for ( int j = 0; j < size_RC; j++) {
if(tbl[a][j] > tbl[largestRow][largestCol]) {
largestRow = a;
largestCol = j;
}
}
}
}
3. For printing the Array
void printArray(int tbl[size_RC][size_RC]) {
for (int a = 0; a < 10; a++) {
for ( int j = 0; j < 10; j++) {
cout << tbl[a][j];
}
}
}
Hope it helps for getting all the functions done.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.