Question

Operations on square matrices. Complete the following C program:
#include <stdio .h>
#define MAXN 20
void print mat (double mat[MAXN] [MAXN] , int n );
void init mat (double mat[MAXN] [MAXN] , int n );
void read mat (double mat[MAXN] [MAXN] , int ∗n );
void print row sums (double mat[MAXN] [MAXN] , int n );
void print diagonal (double mat[MAXN] [MAXN] , int n );
double minimum(double mat[MAXN] [MAXN], int n);
int main(void){ int sz1 , sz2 ;
double mat[MAXN] [MAXN] ;
sz1 = 3;
init mat (mat, sz1 ); int n );
print mat (mat, sz1 );
print row sums (mat, sz1 );
print diagonal (mat, sz1 );
printf (”The minimum of all elements is %8.2 l f \n” , minimum(mat, sz1 ));
// test 2
read mat (mat,&sz2 );
print mat (mat, sz2 );
print row sums (mat, sz2 );
print diagonal (mat, sz2 );
printf (”The minimum of all elements is %8.2 l f \n” , minimum(mat, sz2 ));
}
The following functions must be written:
(a) void print mat(double mat[MAX N][MAX N], int n) — print the matrix one row per line. Print two decimal place for each number.
(b) void init mat(double mat[MAX N][MAXN], int n) — initialize the matrix with the numbers 1.0,2.0,...,n × n.
(c) void read mat(double mat[MAX N][MAXN], ?? n) — read the number of rows n, followed by n × n double values. The values are presented one row per line. Please fill in the type of n.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

void read_mat ( double mat [MAX_N] [MAX_N] , int * n ){
    int i;
    int j;
    double temp;
    int size;
   
    // read the number of rows n
    scanf("%d", n);
   
    // to make sure that the program won't be overflowed   
    size = *n <= MAX_N ? *n : MAX_N;
       // read n * n double values
    for (i = 0; i < size; i++) {
       for (j = 0; j < size; j++) {
            scanf("%lf", &temp);
            mat[i][j] = temp;
       }
    }...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Variable Length Encoding Using C Programming
Homework Solution
$84.00
Computer Science
C Programming
Variable Length Encoding
Standard Output
Sequences of Bits
Strings
Characters
Zeros
Stream
Text Files
Huffman Code
Functions
Using a Linked List in C++.
Homework Solution
$20.00
Computer Science
C++ Programming
Algorithms
Classes
Linked Lists
Boxes
Dimensions
Positive Numbers
Functions
Statements
Variables
Loops
Multiple Dimensioned Array Manipulations
Homework Solution
$33.00
Computer Science
C++ Programming
Array Manipulations
Integers
Factories
Production
Shifts
Average Values
Memory
C++ Project: Binary Sort
Homework Solution
$15.00
Computer Science
Binary Sort
C Programming
Denominator
Strings
Fractions
Decimal Values
Integers
Classes
C++ Programming Problems
Homework Solution
$35.00
Computer Science
C++ Programming
Structs
Enums
Codes
Loops
Coordinates
Maps
Arrays
Dynamic Size
Memory
Selections
Building
Stack Using C Programming
Homework Solution
$60.00
Computer Science
C Programming
Stack
Algorithms
Functions
Frames
References
Parameters
Pointer Manipulations
Header Files
Error Checking
Strings
Arrays
Integers
Get help from a qualified tutor
Live Chats