Está en la página 1de 17

/* METODO GAUSS-JORDAN */

#include<iostream>

#include<stdlib.H>

using namespace std;

int main() {system ("color 13");

float a[20][20];

float d;

int i; int j; int k;

float m; float n; float p; float sw; sw = 0;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@"<<endl;

cout<<"@ UNIVERSIDAD POLITECNICA DE PACHUCA @"<<endl;

cout<<"@ MATERIA: PROGRAMACION @"<<endl;

cout<<"@ UNIDAD IV: ARREGLOS UNIDIMENCIONALES, BIDIMENCIONALES @"<<endl;

cout<<"@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

cout<<"@ MATRICULA: 2031118655 @"<<endl;

cout<<"@ GAUSS-JORDAN @"<<endl;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@"<<endl;

while (sw==0) {

cout << "Digite numero de incognitas:" << endl; cin >> m;

cout << "Digite numero de ecuaciones:" << endl; cin >> n;

if (m==n) {

for (i=1;i<=m;i++) {

for (j=1;j<=n+1;j++) {

cout << "Digite elemento [ " << i << "," << j << " ]" << endl; cin >> a[i][j];
}

for (i=1;i<=m;i++) {

d = a[i][i];

for (j=1;j<=n+1;j++) {

a[i][j] = a[i][j]/d;

for (k=1;k<=m;k++) {

if (k!=i) {

p = (-1)*a[k][i];

for (j=1;j<=m+1;j++) {

a[k][j] = p*a[i][j]+a[k][j];

cout << "La matriz solucion es: " << endl; for (i=1;i<=m;i++) {

for (j=1;j<=n+1;j++) {

cout << a[i][j] << endl;

sw = 1;

} else {

cout << "Se necesita igual numero de ecuaciones para igual numero de incognitas" <<
endl;

cout << "Ingrese nuevamente las ecuacion" << endl; sw = 0;

}}cout<<"@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;


return 0; }

/* MATRIZ INVERSA */

#include<iostream>

#include<stdlib.H>

using namespace std;

int main() {system ("color 1F");

float a[20][20]; float h;

int i;

float inv[20][20]; int j;

int k; float m; float n; float p; float sw; sw = 0;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@"<<endl;

cout<<"@ UNIVERSIDAD POLITECNICA DE PACHUCA @"<<endl;

cout<<"@ MATERIA: PROGRAMACION @"<<endl;

cout<<"@ UNIDAD IV: ARREGLOS UNIDIMENCIONALES, BIDIMENCIONALES @"<<endl;


cout<<"@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

cout<<"@ MATRICULA: 2031118655 @"<<endl;

cout<<"@ MATRIZ INVERSA @"<<endl;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@"<<endl;

while (sw==0) {

cout << "Digite numero de filas de matriz:" << endl; cin >> m;

cout << "Digite numero de columnas de matriz:" << endl; cin >> n;

if (m==n) {

cout << "Digite elementos de la matriz:" << endl; for (i=1;i<=m;i++) {

for (j=1;j<=n;j++) {

cin >> a[i][j];

for (i=1;i<=m;i++) {

for (j=1;j<=n;j++) {

if (i==j) {

inv[i][j] = 1;

} else {

inv[i][j] = 0;
for (i=1;i<=m;i++) {

h = a[i][i];

for (j=1;j<=n;j++) {

a[i][j] = a[i][j]/h;

inv[i][j] = inv[i][j]/h;

for (k=1;k<=m;k++) {

if (k!=i) {

p = (-1)*a[k][i];

for (j=1;j<=m;j++) {

a[k][j] = p*a[i][j]+a[k][j];

inv[k][j] = p*inv[i][j]+inv[k][j];

cout << "La matriz inversa es: " << endl; for (i=1;i<=m;i++) {

for (j=1;j<=n;j++) {

cout << inv[i][j] << endl;

sw = 1;

} else {

cout << "No se puede hallar la matriz inversa" << endl; cout << "Ingrese por favor una matriz
cuadrada" << endl; sw = 0;
}

}cout<<"@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

return 0;

/*6. Multiplicacion de Matrices .*/

#include<iostream>

#include<conio.h>

#include<stdlib.H>

using namespace std;

int main() {system ("color F6");

float a[20][20];

float b[20][20];

float c[20][20];

int i; int j; int k;

float m; float n; float p; float q; float sum;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@"<<endl;
cout<<"@ UNIVERSIDAD POLITECNICA DE PACHUCA @"<<endl;

cout<<"@ MATERIA: PROGRAMACION @"<<endl;

cout<<"@ UNIDAD IV: ARREGLOS UNIDIMENCIONALES, BIDIMENCIONALES @"<<endl;

cout<<"@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

cout<<"@ MATRICULA: 2031118655 @"<<endl;

cout<<"@ MULTIPLICACION DE MATRICES @"<<endl;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@"<<endl;

cout << "Ingrese cantidad de filas de la matriz a" << endl; cin >> m;

cout << "Ingrese cantidad de columnas de la matriz a" << endl; cin >> n;

cout << "Ingrese cantidad de filas de la matriz b" << endl; cin >> q;

cout << "Ingrese cantidad de columnas de la matriz b" << endl; cin >> p;

if (n==q) {

for (i=1;i<=m;i++) {

for (j=1;j<=n;j++) {

cout << "a [ " << i << " " << j << " ]" << endl; cin >> a[i][j];

}}

for (i=1;i<=q;i++) {

for (j=1;j<=p;j++) {

cout << "b [ " << i << " " << j << " ]" << endl; cin >> b[i][j];

for (i=1;i<=m;i++) {

for (j=1;j<=p;j++) {

sum = 0;

for (k=1;k<=n;k++) {

sum = sum+a[i][k]*b[k][j];
}

c[i][j] = sum;

}}

cout << "La matriz producto c es: " << endl; for (i=1;i<=m;i++) {

for (j=1;j<=p;j++) {

cout << "c [ " << i << " " << j << " ] = " << c[i][j] << endl;

}}} else {

cout << "La multiplicacion no es posible ya que las columnas de la matriz a " <<endl;

cout << "no es igual a las filas de la matriz b" << endl;

}cout<<"\n@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

return 0;

/*4. Escribe un programa que defina un vector de números y muestre en la salida estándar

el vector en orden inverso-del último al primer elemento. */


#include<iostream>

#include<conio.h>

#include<stdlib.H>

using namespace std;

int main(){system ("color 36");

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@"<<endl;

cout<<"@ UNIVERSIDAD POLITECNICA DE PACHUCA @"<<endl;

cout<<"@ MATERIA: PROGRAMACION @"<<endl;

cout<<"@ UNIDAD IV: ARREGLOS UNIDIMENCIONALES, BIDIMENCIONALES @"<<endl;

cout<<"@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

cout<<"@ MATRICULA: 2031118655 @"<<endl;

cout<<"@ SALIDA INVERSA DE LOS PRIMEROS 5 NUMEROS @"<<endl;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@"<<endl;

int numeros[5] = {1,2,3,4,5}; //Definimos el arreglo

for(int i=4;i>=0;i--){

cout<<numeros[i]<<endl; //Imprimimos el arreglo en orden inverso

}cout<<"\n@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

getch(); return 0;
}

/*3. Escribe un programa que lea de la entrada estándar un vector de números y

muestre en la salida estándar los números del vector con sus índices asociados.*/

#include<iostream>

#include<conio.h>

#include<stdlib.H>

using namespace std;

int main(){system ("color F3");

int numeros[100],n;
cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@"<<endl;

cout<<"@ UNIVERSIDAD POLITECNICA DE PACHUCA @"<<endl;

cout<<"@ MATERIA: PROGRAMACION @"<<endl;

cout<<"@ UNIDAD IV: ARREGLOS UNIDIMENCIONALES, BIDIMENCIONALES @"<<endl;

cout<<"@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

cout<<"@ MATRICULA: 2031118655 @"<<endl;

cout<<"@ SALIDA ORDENADA @"<<endl;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@"<<endl;

cout<<"\nDigite el numero de elementos: "; cin>>n;

for(int i=0;i<n;i++){

cout<<"\nDigite un numero: ";

cin>>numeros[i]; //Guardamos los numeros en el arreglo

for(int i=0;i<n;i++){//Ahora, vamos a mostrar los numeros con sus indices asociados

cout<<i<<" -> "<<numeros[i]<<endl; //Mostrando los numeros

}cout<<"\n@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

getch(); return 0;
}

/*5. Hacer un programa que lea 5 números en un arreglo, los copie a otro

arreglo multiplicados por 2 y muestre el segundo arreglo. */

#include<iostream>

#include<conio.h>

#include<stdlib.H>

using namespace std;

int main(){system ("color 5D");

int numeros[5],numeros2[5];

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@"<<endl;

cout<<"@ UNIVERSIDAD POLITECNICA DE PACHUCA @"<<endl;

cout<<"@ MATERIA: PROGRAMACION @"<<endl;


cout<<"@ UNIDAD IV: ARREGLOS UNIDIMENCIONALES, BIDIMENCIONALES @"<<endl;

cout<<"@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

cout<<"@ MATRICULA: 2031118655 @"<<endl;

cout<<"@ SEGUNDOS ARREGLOS @"<<endl;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@"<<endl;

//Primero vamos a pedir los 5 numeros del primer arreglo

for(int i=0;i<5;i++){

cout<<i+1<<". Digite un numero: "; cin>>numeros[i];

//Ahora, vamos a multiplicar por 2 los elementos del primer arreglo

for(int i=0;i<5;i++){

numeros2[i] = numeros[i]*2;

cout<<"\nMostrando numeros multiplicados por 2:\n\n";

//Luego mostramos el segundo arreglo

for(int i=0;i<5;i++){

cout<<numeros2[i]<<endl;

}cout<<"\n@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

getch(); return 0;

}
/*2. Escribe un programa que defina un vector de números y calcule la multiplicación acumulada
de sus elementos.*/

#include<iostream>

#include<conio.h>

#include<stdlib.H>

using namespace std;

int main(){system ("color F2");

int numeros[5] ={1,2,3,4,5};

int multiplicacion=1;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@"<<endl;

cout<<"@ UNIVERSIDAD POLITECNICA DE PACHUCA @"<<endl;


cout<<"@ MATERIA: PROGRAMACION @"<<endl;

cout<<"@ UNIDAD IV: ARREGLOS UNIDIMENCIONALES, BIDIMENCIONALES @"<<endl;

cout<<"@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

cout<<"@ MATRICULA: 2031118655 @"<<endl;

cout<<"@ VECTOR MULTIPLICACION @"<<endl;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@"<<endl;

for(int i=0;i<5;i++){

multiplicacion *=numeros[i]; //Hacemos la multiplicacion iterativa

cout<<"La multiplicacion de los elementos es: "<<multiplicacion<<endl;

cout<<"\n@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

getch(); return 0;

}
/* 1. Escribe un programa que defina un vector de números y calcule la suma de sus elementos. */

#include<iostream>

#include<conio.h>

#include<stdlib.H>

using namespace std;

int main(){system ("color FD");

int numeros[5] ={1,2,3,4,5};

int suma=0;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@"<<endl;

cout<<"@ UNIVERSIDAD POLITECNICA DE PACHUCA @"<<endl;

cout<<"@ MATERIA: PROGRAMACION @"<<endl;

cout<<"@ UNIDAD IV: ARREGLOS UNIDIMENCIONALES, BIDIMENCIONALES @"<<endl;

cout<<"@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

cout<<"@ MATRICULA: 2031118655 @"<<endl;

cout<<"@ VECTOR SUMA @"<<endl;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@"<<endl;

for(int i=0;i<5;i++){

suma += numeros[i]; //

cout<<"La suma de los elementos del arreglo es: "<<suma<<endl;

cout<<"\n@ AUTOR: VARGAS CARDENAS NAHUM P @"<<endl;

getch(); return 0;
}

También podría gustarte