-
Notifications
You must be signed in to change notification settings - Fork 0
/
Matriz1.java
77 lines (64 loc) · 1.65 KB
/
Matriz1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//----------->Matriz1
import java.util.Scanner;
class Matriz1{
public static void main(String[] args){
double A[][],B[][],C[][];
int n;
Scanner sc = new Scanner(System.in);
System.out.println("Programa que suma y multiplica dos matrices cuadradas nxn");
System.out.print("Deme el valor de n: ");
n = sc.nextInt();
A = new double [n][n];
B = new double [n][n];
C = new double [n][n];
//ENTRADA DATOS MATRIZ A
System.out.println("\nIngresa los datos de la matriz A: ");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.printf("A[%d][%d]: ",(i+1),(j+1));
A[i][j] = sc.nextDouble();
}
System.out.println();
}
//ENTRADA DATOS MATRIZ B
System.out.println("\nIngresa los datos de la matriz B: ");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.printf("B[%d][%d]: ",(i+1),(j+1));
B[i][j] = sc.nextDouble();
}
System.out.println();
}
//SUMA DE MATRICES
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
C[i][j] = A[i][j] + B[i][j];
}
}
//IMPRECION SUMA DE MATRICES
System.out.println("La suma de matrices es: ");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(C[i][j] + "\t");
}
System.out.println();
}
//PRODUCTO DE MATRICES
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
C[i][j] = 0;
for(int k=0;k<n;k++){
C[i][j] = C[i][j]+A[i][k]*B[k][j];//ALGORITMO MULTI MATRICES
}
}
}
//IMPRECION SUMA DE MATRICES
System.out.println("El producto de matrices es: ");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(C[i][j] + "\t");
}
System.out.println();
}
}//FIN MAIN
}//FIN DE LA CLASE