Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. /*
  2. 57. Realizar un algoritmo que lea 2 matrices. Calcular y escribir otra matriz que sea el
  3. producto matricial de la primera por la segunda.
  4. */
  5. package ej57.t4;
  6. import javax.swing.JOptionPane;
  7. import matrizpaq.Matriz;
  8.  
  9. public class Ej57T4 {
  10.  
  11.  
  12. public static void main(String[] args) {
  13. double [][]X,Y,R;
  14. int nfX,ncX,nfY,ncY,nfR,ncR;
  15. X = Matriz.leeMat();
  16. Y = Matriz.leeMat();
  17. nfX = X.length;
  18. ncX = X[0].length;
  19. nfY = Y.length;
  20. ncY = Y[0].length;
  21. if (ncX==nfY) {
  22. R = new double [nfX][ncY];
  23. for (int p = 0; p < nfX; p++) {
  24. for (int q = 0; q < ncY; q++) {
  25. double SM=0;
  26. for (int a = 0; a < ncX; a++) {
  27. SM = X[p][a]*Y[a][q]+SM;
  28. }R[p][q]=SM;
  29. }
  30. }Matriz.escMat(R);
  31. }else{
  32. String error = "El número de columnas de la 1ra matriz y el número de filas de la 2da son diferentes";
  33. JOptionPane.showMessageDialog(null, error);
  34.  
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement