Question: *Write detailed Algorithm according to the given program- in c Language* #include void findMax(int arr[], int m) //find max sum of column and row //calling
*Write detailed Algorithm according to the given program- in c Language*
#include
void findMax(int arr[], int m) //find max sum of column and row //calling function
{
int i, k = 0;
int max = arr[0];
for (i = 1; i < m; i++)
{
if (arr[i] > max)
{
max = arr[i];
k = i;
}
}
printf(" The greatest sum is %d at %d ", max, k);//printing the greatest sum
}
int main()
{
int m, n, i, j, sum = 0, a[10][10], as1[10];
printf("Enter the order of the matrix ");
printf("Enter the numbers of rows of the matrix: ");
scanf_s("%d", &m);
printf("Enter the numbers of columns of the matrix: ");
scanf_s("%d", &n);
for (i = 0;i < m;i++)
{
for (j = 0;j < n;j++)
{
printf("Enter the value of 2D Array:");
scanf_s("%d", &a[i][j]);
}
}
for (i = 0;i < m;i++)
{
printf(" ");
for (j = 0;j < n;j++)
{
printf("%d\t", a[i][j]);
}
}
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
sum = sum + a[i][j];
}
as1[i] = sum;
printf(" Sum of the row %d is = %d ", i, sum);
sum = 0;
}
findMax(as1, m); //to find the max of the row sums
sum = 0;
for (j = 0; j < n; ++j)
{
for (i = 0; i < m; ++i)
{
sum = sum + a[i][j];
}
as1[j] = sum;
printf(" Sum of the column %d is = %d ", j, sum);
sum = 0;
}
findMax(as1, n); //to find the max sum of the coloumn
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
