LENGUAJE DE PROGRAMACIÓN
LABORATORIO – 2
TRABAJO REALIZADO EN
EL
LABORATORIO
 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();
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;
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
 // 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
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
 int Leer2Matrices()
{
cout<<"***** LEER MATRIZ A[n][m] ***** n";
n=3;
m=3;
for (i=1; i<=n; i++)
for (j=1; j<=m; j++)
{
cout<<"A["<<i<<"]["<<j<<"]= "; cin>>A[i][ j];
}
cout<<endl<<endl;
cout<<"***** LEER MATRIZ B[n][m] ***** n";
n=3;
m=3;
for (i=1; i<=n; i++)
for (j=1; j<=m; j++)
{
cout<<"B["<<i<<"]["<<j<<"]= "; cin>>B[i][ j];
}
cout<<endl;
}
 int Sumar2Matrices()
{
cout<<"***** SUMA DE 2 MATRICES ***** n";
n=3;
m=3;
for (i=1; i<=n; i++)
for (j=1; j<=m; j++)
{
S[i][ j] = A[i][ j] + B[i][ j];
}
cout<<endl;
cout<<"***** ESCRIBIR LA SUMA DE LA MATRIZ **** n";
n=3;
m=3;
for (i=1; i<=n; i++)
for (j=1; j<=m; j++)
{
cout<<"S["<<i<<"]["<<j<<"]= "<<S[i][ j]<<endl;
}
}
Tarea LAB-2
MULTIPLICACION DE 2 MATRICES
 MULTIPLICACION DE 2 MATRICES
Código:
#include <iostream>
#define d 3
using std::cout;
using std::cin;
using std::endl;
int main()
{
int i, j, k, a[d][d], b[d][d], c[d][d];
cout << " ***** LEER MATRIZ A ***** " << endl; // LECTURA MATRIZ A
for(i = 0 ; i < d ; i++)
{
for(j = 0 ; j < d ; j++)
{
cout << " Digite un numero [" << i << "][" << j << "]: ";
cin >> a[i][j];
}
}
cout << endl;
for(i = 0 ; i < d ; i++) // ESCRITURA MATRIZ A
{
for(j = 0 ; j < d ; j++)
{
cout << a[i][j] << " ";
if(j == 2)
cout << endl;
}
}
cout << " ************************* ";
cout << endl;
cout << " ***** LEER MATRIZ B ***** " << endl; // LECTURA MATRIZ B
for(i = 0 ; i < d ; i++)
{
for(j = 0 ; j < d ; j++)
{
cout << " Digite un numero [" << i << "][" << j << "]: ";
cin >> b[i][j];
}
 }
cout << endl;
for(i = 0 ; i < d ; i++) // ESCRITURA MATRIZ B
{
for(j = 0 ; j < d ; j++)
{
cout << b[i][j] << " ";
if(j == 2)
cout << endl;
}
}
cout << " ************************* ";
cout << endl;
for(i=0;i<d;i++) // MULTIPLICACION DE 2 MATRICES
{
for(j=0;j<d;j++)
{
c[i][j]=0;
for(k=0;k<d;k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
}
cout << endl << " ***** MULTIPLICACION DE 2 MATRICES ***** " << endl;
cout << endl;
for(i=0;i<d;i++)
{
for(j=0;j<d;j++)
{
cout << c[i][j] << " ";
if(j==2)
cout << endl;
}
}
system("PAUSE");
return 0;
}
DETERMINANTE DE LA MATRIZ
 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;
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 ";
}
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;
}
TRANSPUESTA DE LA MATRIZ
 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];
}
}

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
Lenguaje de programación

Lenguaje de programación

  • 1.
  • 2.
  • 3.
     MATRICES ENDEV 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 () { intOpcion; 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<<"***** SUMADE 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.
     // ZONADE 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<<"***** SUMADE 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
  • 8.
     int Leer2Matrices() { cout<<"*****LEER MATRIZ A[n][m] ***** n"; n=3; m=3; for (i=1; i<=n; i++) for (j=1; j<=m; j++) { cout<<"A["<<i<<"]["<<j<<"]= "; cin>>A[i][ j]; } cout<<endl<<endl; cout<<"***** LEER MATRIZ B[n][m] ***** n"; n=3; m=3; for (i=1; i<=n; i++) for (j=1; j<=m; j++) { cout<<"B["<<i<<"]["<<j<<"]= "; cin>>B[i][ j]; } cout<<endl; }
  • 9.
     int Sumar2Matrices() { cout<<"*****SUMA DE 2 MATRICES ***** n"; n=3; m=3; for (i=1; i<=n; i++) for (j=1; j<=m; j++) { S[i][ j] = A[i][ j] + B[i][ j]; } cout<<endl; cout<<"***** ESCRIBIR LA SUMA DE LA MATRIZ **** n"; n=3; m=3; for (i=1; i<=n; i++) for (j=1; j<=m; j++) { cout<<"S["<<i<<"]["<<j<<"]= "<<S[i][ j]<<endl; } }
  • 17.
  • 18.
  • 19.
     MULTIPLICACION DE2 MATRICES Código: #include <iostream> #define d 3 using std::cout; using std::cin; using std::endl; int main() { int i, j, k, a[d][d], b[d][d], c[d][d]; cout << " ***** LEER MATRIZ A ***** " << endl; // LECTURA MATRIZ A for(i = 0 ; i < d ; i++) { for(j = 0 ; j < d ; j++) { cout << " Digite un numero [" << i << "][" << j << "]: "; cin >> a[i][j]; } } cout << endl; for(i = 0 ; i < d ; i++) // ESCRITURA MATRIZ A { for(j = 0 ; j < d ; j++) { cout << a[i][j] << " "; if(j == 2) cout << endl; } } cout << " ************************* "; cout << endl; cout << " ***** LEER MATRIZ B ***** " << endl; // LECTURA MATRIZ B for(i = 0 ; i < d ; i++) { for(j = 0 ; j < d ; j++) { cout << " Digite un numero [" << i << "][" << j << "]: "; cin >> b[i][j]; }
  • 20.
     } cout <<endl; for(i = 0 ; i < d ; i++) // ESCRITURA MATRIZ B { for(j = 0 ; j < d ; j++) { cout << b[i][j] << " "; if(j == 2) cout << endl; } } cout << " ************************* "; cout << endl; for(i=0;i<d;i++) // MULTIPLICACION DE 2 MATRICES { for(j=0;j<d;j++) { c[i][j]=0; for(k=0;k<d;k++) { c[i][j]=c[i][j]+(a[i][k]*b[k][j]); } } } cout << endl << " ***** MULTIPLICACION DE 2 MATRICES ***** " << endl; cout << endl; for(i=0;i<d;i++) { for(j=0;j<d;j++) { cout << c[i][j] << " "; if(j==2) cout << endl; } } system("PAUSE"); return 0; }
  • 22.
  • 23.
     DETERMINANTE DELA 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; }
  • 27.
  • 28.
     TRANSPUESTA DELA 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***** MATRIZORIGINAL *****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