3. MATRICES EN DEV C ++
SUMA DE ELEMENTOS DE LA MATRIZ PROMEDIO
MAXIMO
MINIMO Y SUMA DE MATRICES
Código:#include <iostream>
#include <math.h>
using namespace std;
// ZONA DE DECLARACIONES PUBLICAS
//# define n 3, m 3;
int i, j, n, m, Sumar, MAX, MIN;
double promediom;
int Matriz[3][3], A[3][3], B[3][3], S[3][3];
int LeerMatriz();
int EscribirMatriz();
int SumarElementos();
int Leer2Matrices();
int Sumar2Matrices();
4. int main ()
{
int Opcion;
do
{
cout<<" ***** MENU ***** nn";
cout<<" 1) LEER UNA MATRIZ n";
cout<<" 2) ESCRIBIR UNA MATRIZ n";
cout<<" 3) SUMA DE ELEMENTOS DE LA MATRIZ n";
cout<<" 4) LECTURA DE 2 MATRICES n";
cout<<" 5) SUMAR 2 MATRICES n";
cout<<" Digite <0> para salir... n";
cout<<" Ingrese una Opcion: "; cin>>Opcion;
switch (Opcion)
{
case 1:
{
cout<<"***** LEER UNA MATRIZ ***** n";
LeerMatriz(); //INVOCACION A LA FUNCION
cout<<"*************************** n";
}; break;
case 2:
{
cout<<"***** ESCRIBIR UNA MATRIZ ***** n";
EscribirMatriz(); //INVOCACION A LA FUNCION
cout<<"******************************* n";
}; break;
5. case 3:
{
cout<<"***** SUMA DE ELEMENTOS DE LA MATRIZ ***** n";
SumarElementos(); //INVOCACION A LA FUNCION
cout<<"******************************* n";
}; break;
case 4:
{
cout<<"***** LECTURA DE 2 MATRICES ***** n";
Leer2Matrices();
cout<<"********************************************** n";
}; break;
case 5:
{
cout<<"***** SUMAR 2 MATRICES ***** n";
Sumar2Matrices();
cout<<"********************************************** n";
}; break;
}// FIN DEL CASE
} while (Opcion != 0);
system ("pause");
return 0;
} //FIN DEL PROGRAMA
6. // ZONA DE FUNCIONES
int LeerMatriz()
{
cout<<"***** LEER UNA MATRIZ ***** n";
n=3;
m=3;
for (i=1; i<=n; i++)
for (j=1; j<=m; j++)
{
cout<<"Matriz["<<i<<"]["<<j<<"]=";cin>>Matriz[i][ j];
}// FIN DEL FOR
}// FIN DE LEER
int EscribirMatriz()
{
cout<<"***** ESCRIBIR UNA MATRIZ ***** n";
n=3;
m=3;
for (i=1; i<=n; i++)
for (j=1; j<=m; j++)
{
cout<<"Matriz["<<i<<"]["<<j<<"]= "<<Matriz[i][ j]<<endl;
}// FIN DEL FOR
}// FIN DE ESCRIBIR
7. int SumarElementos()
{
cout<<"***** SUMA DE ELEMENTOS DE LA MATRIZ ***** n";
n=3;
m=3;
for (i=1; i<=n; i++)
for (j=1; j<=m; j++)
{
Sumar = Sumar + Matriz[i][ j]; //ACUMULADOR
promediom = Sumar / (m*n);
}// FIN DEL FOR
cout<<"La suma de los elementos de la matriz es: "<<Sumar;
cout<<endl<<endl;
cout<<"El Promedio de los Elementos es: "<< promediom;
cout<<endl<<endl;
// MAXIMO
MAX = Matriz[1][1];
for (i=1; i<=n; i++)
for (j=1; j<=m; j++)
{
if (Matriz[i][ j]>MAX)
MAX = Matriz[i][ j];
} // IN DEL FOR
cout<<"El maximo de los elementos de la Matriz es: " <<MAX;
cout<<endl<<endl;
MIN = Matriz[1][1];
for (i=1; i<=n; i++)
for (j=1; j<=m; j++)
{
if (Matriz[i][ j]<MIN)
MIN = Matriz[i][ j];
} // IN DEL FOR
cout<<"El minimo de los elementos de la Matriz es: " <<MIN;
cout<<endl<<endl;
}//FIN DE SUMA DE MATRICES
23. DETERMINANTE DE LA MATRIZ
Código:
#include<iostream>
using namespace std;
int main ()
{
int i,j,k,l,m,n ;
float A[100][100];
float det;
cout << " ***** MATRIZ 3X3 --> N = 3 ****** " << endl; // ORDEN DE LA MATRIZ
cout << " ********************************* " << endl;
cout << " Digitar orden de la matriz: N = ";
cin >> n;
m=n-1;
cout << endl;
24. cout << " ***** INTRODUCIR LOS ELEMENTOS ***** " << endl; // ESCRITURA DE LA
MATRIZ
cout << " ************************************ " << endl;;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
cout <<" Digite un numero ["<<i<<"]["<<j<<"]: ";
cin >> A[i][ j];
}
}
cout<<" n***** MATRIZ ORIGINAL *****n "; // LECTURA DE LA MATRIZ
for(int i=1;i<n+1;i++)
{
for(int j=1;j<n+1;j++)
{
cout<<A[i][ j]<<" ";
}
cout<<"n ";
}
25. det = A[1][1]; // DETERMINANTE DE LA MATRIZ
for(k=1;k<=m;k++)
{
l=k+1;
for(i=l;i<=n;i++)
{
for(j=l;j<=n;j++)
A[i][ j] = ( A[k][k] * A[i][ j] - A[k][ j] * A[i][k] ) / A[k][k];
}
det = det * A[k+1][k+1];
}
cout << endl;
cout << " ***** LA DETERMINANTE ES: ***** " << det << endl;
cout << " ******************************* " << endl;
system("PAUSE");
return 0;
}
28. TRANSPUESTA DE LA MATRIZ
Código:
#include<iostream>
#include<conio.h>
using namespace std;
// ZONA DE DECLARACIONES PUBLICAS
int A[3][3];
int main()
{
cout<<" ***** MATRIZ 3X3 ***** ";
cout<< endl;
for(int i=0;i<3;i++) // ESCRITURA DE LA MATRIZ
{
for(int j=0;j<3;j++)
{
cout<<" Digite un numero ["<<i<<"]["<<j<<"]: ";
cin>>A[i][ j];
}
}
29.
cout<<" n***** MATRIZ ORIGINAL *****n "; // LECTURA DE LA MATRIZ
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<A[i][ j]<<" ";
}
cout<<"n ";
}
cout<< endl;
cout<<" n***** MATRIZ TRANSPUESTA *****n "; // TRANSPUESTA DE LA MATRIZ
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<A[ j][i]<<" ";
}
cout<<" n ";
}
getch();
return 0;
} // FIN DEL PROGRAMA