In main do the following: Declare a 2-d integer array with 4 rows and 6 columns
ID: 3833215 • Letter: I
Question
In main do the following: Declare a 2-d integer array with 4 rows and 6 columns (You may use symbolic (define) columns for the number of rows and the number of columns). Seed random number generator with the current time. Call function Fill2DArrayRandom to fill inclusive Numarray with random numbers on the inclusive range [0, 9]. Print randomNumArray to stdout (the console screen). Prompt the user to enter a number between 0 and 5-repeating until they enter a valid one-called replaceColumnIndesx. Call ReplaceColumnWithIntegral to replace all elements in the column chosen by replaceColumnIndex in randomNumArray with 10. Print randomNumArray to Stdout (th3e console screen.) Test your program to ensure that it is working correctly. This function receives the following input parameters: a 2D integer array, the minimum random value (min Val), and the minimum random value (max Val). This function has no return value. The function will fill each element of the passed in 2D with an random number on the (inclusive) range from the interval [min Val, max Val]. This function receives an input 2D integer array, the number of columns in the array, and the column index to replace. This function has no return value. This function will replace all elements of the specified column in the input 2D array the value 10. For instance, if the input integer array originally had the following 5 elements in the first row: {7, 0, 6, 2, 9, 4, ...} and the replacement column was 2, this function would result in {7, 0, 10, 2, 9, 4, ...} and so on. You may do this problem entirely in main with a substantial deduction of points.Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void Fill2DArrayRandom( int (&data)[10][10], int minVal, int maxVal) //Assuming 2D array is 10 x 10
{
int i, j;
srand(time(NULL));
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10; j++)
{
data[i][j] = rand() % maxVal + minVal;
}
}
return;
}
void ReplaceColumnWithInteger( int **data, int rows, int cols, int colindex)
{
int i;
if (colindex < 0 || colindex >= cols){
cout << "Error:Invalid column Index" << endl;
return;
}
for (i=0; i<rows; i++){
data[i][colindex] = 10;
}
return;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.