ayuda con matrices
quiero un programa que haga lo siguiente utilizando punteros
1. obtener elemento. que devuelva el elemento de fila i y la columna j de la matriz m
2. Asignae elemento. asigna el valor x al elemento de la gila i y columna j de la matriz m
3. Asignar. asigna los elementos de la matriz m1 a la matriz m2
4. sumar dos matrices de la misma dimension
5. negativa. devuelve la matriz que resulta de cambiar el signo a los elementos de la matriz m
6. restar dos matrices
7. producto escalar.- devuelve la matriz despues de multiplicar la matriz m por un escalar e
8. multimplicar dos matrices
9. matriz transpúesta
10. determinante de la matriz
11. inversa de la matriz
si alguno tiene aunque noo sea con punteros por favor mandelo al mi correo [email protected]
Te envio un programa que realiza parte de las operaciones pedidas, con la esperanza de que ayude a completar lo que falta
// program k5a3.CPP - page 77
// for the given matrix of integers : a(5x5), b(5x5), c(1x5), d(5x1)
// calculate : 1 - a + b
// 2 - a * b
// 3 - a * d
// 4 - c * d
// c++ exercices book - dr. gershon kagan (first edition : 2001)
// written in Borland CPP ver 3.1
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#define MAX 5
enum direction {horizontal,vertical};
void Init(int a[][MAX],int M, int N)
{
for(int i = 0; i < M; i++)
for(int j = 0; j < N; j++)
a[i][j] = random(20) + 1;
} // INIT MATRIX
void Init(int a[],int M)
{
for(int i = 0; i < M; i++)
a[i] = random(20) + 1;
} // INIT ARRAY
void Show(int *a,int M, int N)
{
for(int i = 0; i < M; i++)
{
for(int j = 0; j < N; j++)
cout << setw(6) << *(a+M*i+j);
cout << endl;
}
cout << endl;
} // SHOW MATRIX
void Show(int *a,int M,direction x)
{
for(int i = 0; i < M; i++)
{
cout << setw(6) << a[i];
if(x == vertical)
cout << endl;
}
cout << endl << endl;
} // SHOW ARRAY
void ProcessOne(int a[][MAX],int b[][MAX])
{
clrscr();
cout << "sum = a + b" << endl << endl;
int sum[MAX][MAX];
for(int i = 0; i < MAX; i++)
for(int j = 0; j < MAX; j++)
sum[i][j] = a[i][j] + b[i][j];
Show(&a[0][0],MAX,MAX);
Show(&b[0][0],MAX,MAX);
Show(&sum[0][0],MAX,MAX);
getch();
} // PROCESS ONE
void ProcessTwo(int a[][MAX],int b[][MAX])
{
clrscr();
cout << "mult = a * b" << endl << endl;
int mult[MAX][MAX];
for(int i = 0; i < MAX; i++)
for(int j = 0; j < MAX; j++)
{
mult[i][j] = 0;
for(int k = 0; k < MAX; k++)
mult[i][j] += a[i][k]*b[k][j];
}
Show(&a[0][0],MAX,MAX);
Show(&b[0][0],MAX,MAX);
Show(&mult[0][0],MAX,MAX);
getch();
} // PROCESS TWO
void ProcessThree(int a[MAX][MAX],int d[MAX])
{
clrscr();
cout << "mult = a * d" << endl << endl;
int mult[MAX];
for(int i = 0; i < MAX; i++)
{
mult[i] = 0;
for(int j = 0; j < MAX; j++)
mult[i] += a[i][j]*d[j];
}
Show(&a[0][0],MAX,MAX);
Show(d,MAX,vertical);
Show(mult,MAX,vertical);
getch();
} // PROCESS THREE
void ProcessFour(int c[MAX],int d[MAX])
{
clrscr();
cout << "mult = c * d" << endl << endl;
int mult = 0;
for(int i = 0; i < MAX; i++)
mult += c[i]*d[i];
Show(c,MAX,horizontal);
Show(d,MAX,vertical);
cout << setw(6) << mult << endl << endl;
} // PROCESS FOUR
void main()
{
randomize();
int a[MAX][MAX],b[MAX][MAX],c[MAX],d[MAX];
Init(a,MAX,MAX);
Init(b,MAX,MAX);
Init(c,MAX);
Init(d,MAX);
ProcessOne(a,b);
ProcessTwo(a,b);
ProcessThree(a,d);
ProcessFour(c,d);
cout << "end of program - good bye ! ! !n";
getch();
} // MAIN
/*
sum = a + b
12 5 12 4 13
5 15 14 9 16
3 13 10 8 19
4 3 10 20 5
5 8 5 5 17
14 7 8 2 1
17 18 12 4 5
10 10 13 20 15
9 4 8 14 12
13 10 19 4 17
26 12 20 6 14
22 33 26 13 21
13 23 23 28 34
13 7 18 34 17
18 18 24 9 34
mult = a * b
12 5 12 4 13
5 15 14 9 16
3 13 10 8 19
4 3 10 20 5
5 8 5 5 17
14 7 8 2 1
17 18 12 4 5
10 10 13 20 15
9 4 8 14 12
13 10 19 4 17
578 440 591 392 486
754 641 778 540 670
682 577 735 446 637
452 312 453 520 494
522 419 564 280 469
mult = a * d
12 5 12 4 13
5 15 14 9 16
3 13 10 8 19
4 3 10 20 5
5 8 5 5 17
16
14
12
17
6
552
707
600
596
439
mult = c * d
18 13 4 13 4
16
14
12
17
6
763
end of program - good bye ! ! !
*/
// program k5a3.CPP - page 77
// for the given matrix of integers : a(5x5), b(5x5), c(1x5), d(5x1)
// calculate : 1 - a + b
// 2 - a * b
// 3 - a * d
// 4 - c * d
// c++ exercices book - dr. gershon kagan (first edition : 2001)
// written in Borland CPP ver 3.1
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#define MAX 5
enum direction {horizontal,vertical};
void Init(int a[][MAX],int M, int N)
{
for(int i = 0; i < M; i++)
for(int j = 0; j < N; j++)
a[i][j] = random(20) + 1;
} // INIT MATRIX
void Init(int a[],int M)
{
for(int i = 0; i < M; i++)
a[i] = random(20) + 1;
} // INIT ARRAY
void Show(int *a,int M, int N)
{
for(int i = 0; i < M; i++)
{
for(int j = 0; j < N; j++)
cout << setw(6) << *(a+M*i+j);
cout << endl;
}
cout << endl;
} // SHOW MATRIX
void Show(int *a,int M,direction x)
{
for(int i = 0; i < M; i++)
{
cout << setw(6) << a[i];
if(x == vertical)
cout << endl;
}
cout << endl << endl;
} // SHOW ARRAY
void ProcessOne(int a[][MAX],int b[][MAX])
{
clrscr();
cout << "sum = a + b" << endl << endl;
int sum[MAX][MAX];
for(int i = 0; i < MAX; i++)
for(int j = 0; j < MAX; j++)
sum[i][j] = a[i][j] + b[i][j];
Show(&a[0][0],MAX,MAX);
Show(&b[0][0],MAX,MAX);
Show(&sum[0][0],MAX,MAX);
getch();
} // PROCESS ONE
void ProcessTwo(int a[][MAX],int b[][MAX])
{
clrscr();
cout << "mult = a * b" << endl << endl;
int mult[MAX][MAX];
for(int i = 0; i < MAX; i++)
for(int j = 0; j < MAX; j++)
{
mult[i][j] = 0;
for(int k = 0; k < MAX; k++)
mult[i][j] += a[i][k]*b[k][j];
}
Show(&a[0][0],MAX,MAX);
Show(&b[0][0],MAX,MAX);
Show(&mult[0][0],MAX,MAX);
getch();
} // PROCESS TWO
void ProcessThree(int a[MAX][MAX],int d[MAX])
{
clrscr();
cout << "mult = a * d" << endl << endl;
int mult[MAX];
for(int i = 0; i < MAX; i++)
{
mult[i] = 0;
for(int j = 0; j < MAX; j++)
mult[i] += a[i][j]*d[j];
}
Show(&a[0][0],MAX,MAX);
Show(d,MAX,vertical);
Show(mult,MAX,vertical);
getch();
} // PROCESS THREE
void ProcessFour(int c[MAX],int d[MAX])
{
clrscr();
cout << "mult = c * d" << endl << endl;
int mult = 0;
for(int i = 0; i < MAX; i++)
mult += c[i]*d[i];
Show(c,MAX,horizontal);
Show(d,MAX,vertical);
cout << setw(6) << mult << endl << endl;
} // PROCESS FOUR
void main()
{
randomize();
int a[MAX][MAX],b[MAX][MAX],c[MAX],d[MAX];
Init(a,MAX,MAX);
Init(b,MAX,MAX);
Init(c,MAX);
Init(d,MAX);
ProcessOne(a,b);
ProcessTwo(a,b);
ProcessThree(a,d);
ProcessFour(c,d);
cout << "end of program - good bye ! ! !n";
getch();
} // MAIN
/*
sum = a + b
12 5 12 4 13
5 15 14 9 16
3 13 10 8 19
4 3 10 20 5
5 8 5 5 17
14 7 8 2 1
17 18 12 4 5
10 10 13 20 15
9 4 8 14 12
13 10 19 4 17
26 12 20 6 14
22 33 26 13 21
13 23 23 28 34
13 7 18 34 17
18 18 24 9 34
mult = a * b
12 5 12 4 13
5 15 14 9 16
3 13 10 8 19
4 3 10 20 5
5 8 5 5 17
14 7 8 2 1
17 18 12 4 5
10 10 13 20 15
9 4 8 14 12
13 10 19 4 17
578 440 591 392 486
754 641 778 540 670
682 577 735 446 637
452 312 453 520 494
522 419 564 280 469
mult = a * d
12 5 12 4 13
5 15 14 9 16
3 13 10 8 19
4 3 10 20 5
5 8 5 5 17
16
14
12
17
6
552
707
600
596
439
mult = c * d
18 13 4 13 4
16
14
12
17
6
763
end of program - good bye ! ! !
*/
programa para la matriz transpuesta:
#include <conio.h>
#include <iomanip.h>
#include <iostream.h>
void main()
{
clrscr();
const int M = 2, N = 5;
int a[M][N] = {0,1,2,3,4,5,6,7,8,9}, b[N][M];
for(int i = 0; i < M;i++)
{
for(int j = 0;j < N;j++)
{
cout << setw(5) << a[i][j];
b[j][i] = a[i][j];
}
cout << endl;
}
cout << "--------------------------------------" << endl;
for(i = 0; i < N;i++)
{
for(int j = 0;j < M;j++)
cout << setw(5) << b[i][j];
cout << endl;
}
} // MAIN
#include <conio.h>
#include <iomanip.h>
#include <iostream.h>
void main()
{
clrscr();
const int M = 2, N = 5;
int a[M][N] = {0,1,2,3,4,5,6,7,8,9}, b[N][M];
for(int i = 0; i < M;i++)
{
for(int j = 0;j < N;j++)
{
cout << setw(5) << a[i][j];
b[j][i] = a[i][j];
}
cout << endl;
}
cout << "--------------------------------------" << endl;
for(i = 0; i < N;i++)
{
for(int j = 0;j < M;j++)
cout << setw(5) << b[i][j];
cout << endl;
}
} // MAIN
