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
Consider the array:
int a[]={12, 35, 40, 22, 56, 9, 70};(a) In the above given array, using linear search, how many iterations are required to check for the existence of the value 56?
(b) If the array is arranged in descending order, how many iterations are required to check for the existence of 56 using linear search?
Evaluate the expression:
3 * 6 % 5 * 4 / 2 * 7 % 5
Give the output of the following program segment:
for(r=1;r<=3;r++) { for(c=1;c<r;c++) { System.out.println(r); } }Give the output of the following program segment:
void encode() { String s= "DICe"; char ch; for(i=0;i<4;i++) { ch=s.charAt(i); if("AEIOUaeiou".indexOf(ch)>=0) System.out.println("@"); else System.out.println(ch); }