Question
Write a program that ask user to enter two integers X and Y, and two doubles minZ maxZ. It then allocates a dynamic 2D array
Write a program that ask user to enter two integers X and Y, and two doubles minZ maxZ. It then allocates a dynamic 2D array consisting of X rows and Y columns of double values, and sets each value in the 2D array by randomly generating a number between minZ and maxZ. If (minZ == maxZ), then simply set each value in the 2D array to minZ. Then print the overall sum, the sum of each row, and the sum of each column.
Here is a sample output: When input is 5 3 2.0 2.0 for X Y minZ maxZ Standard output starts with Overall sum = 30.0
Sum of each row
Row0 = 6.0
Row1 = 6.0
Row2 = 6.0
Row3 = 6.0
Row4 = 6.0
Sum of each column
10.0 10.0 10.0
#include #include
double RandomReal(double low, double high){
double d;
d = (double) rand() / ((double) RAND_MAX + 1);
return (low + d * (high - low));
}
int main(int argc, char* argv[]) {
int X, Y;
double minZ, maxZ; double **Arr2D; printf("Enter X Y minZ maxZ:");
scanf("%d %d %lf %lf", &X, &Y, &minZ, &maxZ);
/* dynamically create 2D array of doubles (X row, Y col),
* For each i, j * if (minZ == maxZ) Arr2D[i][j] = minZ;
* else Arr2D[i][j] = RandomReal(minZ, maxZ);
* Then find the sums we want using the given Arr2D !
*/
/* YOUR CODE */ return 0; } /* Dont forget to include comments about the problem, yourself and each major step in your program! */
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