KnowledgeBoat Logo
|

Computer Applications

Consider the following program which calculates the Norm of a matrix. Norm is square root of sum of squares of all elements.

Fill in the blanks (a) and (b) with appropriate java statements:

double norm() 
{ int x[][]={{1,5,6},{4,2,9},{6,1,3}}; 
int r, c, sum=0; 
for(r=0;r<3;r++) 
{ for(c=0;c<3;c++) 
   sum=sum+_____(a)_____; 
} 
____(b)________; 
}

Java Arrays

1 Like

Answer

double norm() 
{ int x[][]={{1,5,6},{4,2,9},{6,1,3}}; 
int r, c, sum=0; 
for(r=0;r<3;r++) 
{ for(c=0;c<3;c++) 
   sum=sum+x[r][c] * x[r][c];
} 
return Math.sqrt(sum);
}

Answered By

1 Like


Related Questions