Written by: Nancy Lamm This program fills a two-dinensional array and then finds
ID: 3816273 • Letter: W
Question
Written by: Nancy Lamm This program fills a two-dinensional array and then finds the naxinum value Sn each row and column C tt int main() //Print the 2-D array printf("VnArray values n printf //Find naxinum value in each row and print as they are calculated for (rwe; re-3; r++ for (e-e; co-4; c..) if (nunCr nun [in][c]; printf Maxinum for row Ad is n", r max) //Find naximum value in each row and store in a 1-D array for (c-e: cc-4 c..) //Print maximum values from printf WRow Maxinumwn"); for (rwe; r Ji r++) return 0 Classwork Enter the program above. After executing it successfully make the following changes: 1. Instead of initializing the array at declaration, use a nested loop to assign random numbers between 1 to the array 2. Define constants ROM and cou with the number of nows and columns and write linits for all loops as Row-1 or COL-1 3. Find the maximum of each colunn. Store in a one-D array. Print fron the array 4. Find the maximum value of all the elements in the array. 5. Change the size of the array to 6 rows and 6 colums and execute the program again.Explanation / Answer
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
srand(time(NULL));
int arr[5][5];
int ROW=0, COL=0;
int max=50;
int min =1;
int maxArr[5];
for(ROW=0;ROW<5;ROW++){
for(COL=0;COL<5;COL++){
int randomno = rand()%(max-min) + min;
arr[ROW][COL] = randomno;
}
}
int i=0;
max = arr[0][0];
for(COL=0;COL<5;COL++){
for(ROW=0;ROW<5;ROW++){
if(max < arr[COL][ROW])
max = arr[COL][ROW];
}
maxArr[i] =max;
i++;
}
printf(" Maximum of each column are :");
max = maxArr[0];
for(i=0;i<5;i++){
printlf(" %d ",maxArr[i]);
if(max<maxArr[i])
max = maxArr[i];
}
printf(" Maximum of each column is: %d",max);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.