Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program in C++ using the simplest code posssible that will read data fr

ID: 2991031 • Letter: C

Question

Create a program in C++ using the simplest code posssible that will read data from a file to fill a two dimensional array, output the array and determine the sum of each column and the sum of each row. Your program should have 4 functions: one to input the data from the file into the array, one to output the array, one to sum each column and send back to the function call these sums as an array, and one to sum each row and send back to the function call these sums as an array. Your main function should call all the functions.

       You should assume that the array will not contain more than 25 rows and 15 columns. The actual number of rows and columns is given in the first row the file. The data is all whole numbers

Explanation / Answer

void main ()
{
static int array[10][10];
int i, j, m, n, sum = 0;

printf("Enter the order of the matrix ");
scanf("%d %d", &m, &n);
printf("Enter the co-efficients of the matrix ");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
scanf("%d", &array[i][j]);
}
}
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
sum = sum + array[i][j] ;
}
printf("Sum of the %d row is = %d ", i, sum);
sum = 0;
}
sum = 0;
for (j = 0; j < n; ++j)
{
for (i = 0; i < m; ++i)
{
sum = sum + array[i][j];
}
printf("Sum of the %d column is = %d ", j, sum);
sum = 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote