-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuma_vectores.cpp
57 lines (47 loc) · 1.06 KB
/
suma_vectores.cpp
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
#include <iostream>
#include <cmath>
using namespace std;
void imp_matriz(int vec[], int tamano){
int x = 0, j = 0;
for (int i = 0; i < round(sqrt(tamano)); i++){
x = 0;
cout << "[";
while (x != round(sqrt(tamano))){
cout << vec[j] << " ";
j++;
x++;
}
cout << "]\n";
}
}
void sumar_matriz(int vec1[], int vec2[], int tamano1, int tamano2){
int x = 0, j = 0;
for (tamano1; tamano1 < tamano2; tamano1++){
vec1[tamano1] = 0;
}
for (tamano2; tamano2 < tamano1; tamano2++){
vec2[tamano2] = 0;
}
for (int i = 0; i < round(sqrt(tamano1)); i++){
x = 0;
cout << "[";
while (x != round(sqrt(tamano1))){
cout << vec1[j]+vec2[j] << " ";
j++;
x++;
}
cout << "]\n";
}
}
main(){
int vectA[] = {1, 0, 0, 1};
int vectB[] = {0, 1, 0, 0};
int t_vectA = sizeof(vectA)/sizeof(vectA[0]);
int t_vectB = sizeof(vectB)/sizeof(vectB[0]);
cout << "\nMatriz A: \n";
imp_matriz(vectA, t_vectA);
cout << "\nMatriz B: \n";
imp_matriz(vectB, t_vectB);
cout << "\nLa matriz de salida C es: \n";
sumar_matriz(vectA, vectB, t_vectA, t_vectB);
}