error: cannot convert "int (*)[c]" to "int*" for argument "1"
Publicado por Elena (3 intervenciones) el 18/11/2018 22:08:23
Estoy intentando hacer un programa con ficheros y arrays donde se muestren matrices, se rellenen, se calcule la suma, el producto por escalar y el producto entre dos matrices, y el compilador me da el siguiente error:
error: cannot convert 'int (*)[c]' to 'int*' for argument '1' to 'void RellenarMatrices(int*, int)'|
Os dejo el codigo a ver si me podeis ayudar.
Las funciones están aquí:
Solo me da error en la primera parte, dentro del int main, en lo demás no.
Gracias.
error: cannot convert 'int (*)[c]' to 'int*' for argument '1' to 'void RellenarMatrices(int*, int)'|
Os dejo el codigo a ver si me podeis ayudar.
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
#include <iostream>
#include "matrices.hpp"
using namespace std;
int main()
{
int f, c, escalar, prodescalar;
int a[f][c], b[f][c], r[f][c], s[f][c], p[f][c];
cout << "Introduzca el numero de filas de las matrices: ";
cin >> f;
cout << "Introduzca el numero de columnas de las matrices: ";
cin >> c;
cout << "Introduzca un escalar: ";
cin >> escalar;
RellenarMatrices(a, f, c);
RellenarMatrices(b, f, c);
MostrarMatrices(a, f, c);
MostrarMatrices(b, f, c);
prodescalar = ProductoMatrizEscalar(a, r, f, c, escalar);
s = SumaMatrices(a, b, s, f, c);
p = ProductoMatrices(a, b, p, f, c, c);
cout << "La suma es: " << MostrarMatrices(s, f, c) << endl;
cout << "El producto por el escalar " << escalar << "es: " << MostrarMatrices(r, f, c) << endl;
cout << "El producto de las dos matrices es: " << MostrarMatrices(p, f, c) << endl;
return 0;
}
Las funciones están aquí:
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
#include "matrices.hpp"
/**Calcular el producto de una matriz por un escalar**/
void ProductoMatrizEscalar(int a[][100], int r[][100], int f, int c, int escalar)
{
int i, j;
for(i=0; i<f; i++)
for(j=0; j<c; j++)
r[i][j] = escalar*a[i][j];
return;
}
/**Calcular la suma de dos matrices**/
void SumaMatrices(int a[][100], int b[][100], int r[][100], int f, int c)
{
int i, j;
for(i=0; i<f; i++)
for(j=0; j<c; j++)
r[i][j] = a[i][j] + b[i][j];
return;
}
/**Calcular el producto de dos matrices**/
void ProductoMatrices(int a[][100], int b[][100], int r[][100], int f1, int c1, int c2)
{
int i, j, k;
for(i=0; i<f1; i++)
for(j=0; j<c1; j++)
{
r[i][j] = 0;
for(k=0; k<c2; k++)
r[i][j] = a[i][k]*b[k][j];
}
return;
}
/**Rellenar matrices**/
void RellenarMatrices(int m[][100], int nfils, int ncols)
{
int i, j;
for(i=0; i<nfils; i++)
for(j=0; j<ncols; j++)
{
cout << "Elemento [" << i+1 << "," << j+1 << "]: ";
cin >> m[i][j];
}
return;
}
/**Mostrar matrices**/
void MostrarMatrices(int m[][100], int nfils, int ncols)
{
int i, j;
for(i=0; i<nfils; i++)
for(j=0; j<ncols; j++)
{
cout << "Elemento [" << i+1 << "," << j+1 << "]: ";
cout << m[i][j] << endl;
}
return;
}
Solo me da error en la primera parte, dentro del int main, en lo demás no.
Gracias.
Valora esta pregunta
0