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

Using C language do not need to be complicated 2. [8] A diagonally dominant matr

ID: 3593906 • Letter: U

Question

Using C language do not need to be complicated

2. [8] A diagonally dominant matrix is a matrix A such that for each row, the absolute value of the diagonal element on that row is strictly larger than the sum of the absolute values of all other elements in the row. That is, for each row i-0,1,..., n-l, the following holds: j=0 ,jti Write a function is_diag_dom() that determines if an N-by-N matrix mat is diagonally dominant (it returns 1 if the matrix is diagonally dominant and 0 otherwise). The function prototype has to be int is, diag, dom( int mat[ ][N]). · You may use the function fabs()with prototype double fabs(double x), from the C standard math library, which returns the absolute value of x. Write a program to test this function. Note that N represents a constant. To set a value to N use the define directive at the beginning of the file (E. g: #define N 20 replaces N by 20 all over the file, except for occurrences of N inside a string r variable name), Writea prognam to test the function.

Explanation / Answer

PLEASE REFER BELOW CODE

#include<stdlib.h>
#include<stdio.h>

#define N 3

int is_diag_dom(int mat[][N])
{
int i,j,sum;
int flag = 1;
int diag_ele;
for(i = 0; i < N; i++)
{
sum = 0; //sum for all non-diagonal element of row
diag_ele = mat[i][i]; //diagonal element
//loop for all rows and columns of matrix
for(j = 0; j < N; j++)
{
if(i != j) //for non-diagonal element
{
sum = sum + mat[i][j];
}
}
if(sum > diag_ele) //if sum of all row element is greater than diagonal then return 0 else return 1
{
flag = 0;
break;
}

}
return flag;
}

int main()
{
int mat[N][N] = {{4,1,2}, {2,6,3}, {6,7,19}}; //taking sample matrix which is diagonally dominant
int flag;

flag = is_diag_dom(mat); //calling function

if(flag) //if function returns 1 then it's diagonally dominant otherwise not
printf("Matrix is diagonally dominant ");
else
printf("Matrix is NOT diagonally dominant ");

return 0;
}

HERE I TOOK MATRIX INPUT AS

4 1 2

2 6 3

6 7 19

PLEASE REFER BELOW OUTPUT

Matrix is diagonally dominant

Process returned 0 (0x0) execution time : 0.026 s
Press any key to continue.

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