MATRIZ

3  EJEMPLOS EN C++ MATRIZ :

/* 
ALUMNO: FERNANDEZ ANCASI TERRY WILLIAMS
INGENIERIO: ROMAN MUNIVE WILDER
EJERCICIOS DEV-C++ USO DE MATRIZ:
 
           
          cout << "QUE TENGA BUEN DIA"; 
*/
using namespace std;
#include <iostream>
#include <iomanip.h>
#include <conio.h>
#include <math.h>
int main()
{
    int **pm;

    int cl;
    int rw;
    cout << setw(61) << "ALUMNO: FERNANDEZ ANCASI  TERRY WILLIAMS"<<endl<<endl;
    cout << setw(55) << "INGENIERO: ROMAN MUNIVE WILDER" << endl << endl;
    cout << "\n";
    cout<<setw(57)<<"MATRIZ DINAMICA USANDO ARITMETICA";
    cout<<"\n\n";
    cout << "Ingresa el numero de filas: ";
    cin >> rw;

    cout << endl;
    cout << "Ingresa el numeroro de columnas: ";
    cin >> cl;

    pm = new int* [rw];
    for (int i = 0; i < rw; i++) {
        pm[i] = new int[cl];
    }

    cout << "Elementos de la Matriz con sus direcciones:\n " << endl;
    for (int i = 0; i < rw; i++) {
        for (int j = 0; j < cl; j++) {
            pm[i][j] = i + j;
            cout << pm[i][j] << "--> ";
            cout << &pm[i][j] << endl;
        }
        cout << endl;
    }
    cout << endl;

    cout<<"Elementos de la Matriz con sus direcciones, con aritmetica de punter          os:\n " << endl;
    for (int i = 0; i < rw; i++) {
        for (int j = 0; j < cl; j++) {
            *(*(pm + i) + j) = i + j;
            cout << *(*(pm + i) + j) << "--> ";
            cout << &pm[i][j] << endl;
        }
        cout << endl;
    }

    
    for (int i = 0; i < rw; i++) {
        delete[] pm[i];
    }

    // Elimino el vector principal
    delete[] pm;
    cout<<setw(50)<<"QUE TENGA BUEN DIA";
    getch();
}
                     EJEMPLO 2:
/*  PRIMER PARCIAL
ALUMNO: FERNANDEZ ANCASI TERRY WILLIAMS
INGENIERIO: ROMAN MUNIVE WILDER
EJERCICIOS DEV-C++ DE LA MATRIZ
           
          cout << "QUE TENGA BUEN DIA"; 
*/
using namespace std;
#include<iostream>
#include<iomanip>
#include<conio.h>
#include<math.h>
int main()
{
int matriz[50][50],X,Y,i,k;
cout<<setw(61) << "ALUMNO: FERNANDEZ ANCASI  TERRY WILLIAMS"<<endl<<endl;
cout<<setw(55) << "INGENIERO: ROMAN MUNIVE WILDER"<<endl<< endl;
cout<<"\n";
cout<<setw(60)<<"CALCULO DE LA TRANSPUESTA DE LA MATRIZ";
cout<<"\n\n";
cout<<"Numero de Columnas de la Matriz: ";cin>>X;
cout<<"\n";
cout<<"Numero de Filas de la Matriz: ";cin>>Y;
cout<<"\n";
for(i=0;i<Y;i++)
{
for(k=0;k<X;k++)
{
cout<<"\t Valor de la Matriz en la fila "<<i+1<<" columna "<<k+1<<": ";
cin>>matriz[i][k];
}
}
cout<<"\n\n ESTA ES LA MATRIZ ORIGINAL";
cout<<"\n";
for(i=0;i<Y;i++)
{
cout<<"\n";
for(k=0;k<X;k++)
{
if(matriz[i][k]<10)
cout<<" "<<matriz[i][k];
else
cout<<" "<<matriz[i][k];
}
}
cout<<"\n\n";
cout<<"ESTA ES LA TRASPUESTA DE LA MATRIZ ORIGINAL";
cout<<"\n";
for(i=0;i<X;i++)
{
cout<<"\n";
for(k=0;k<Y;k++)
{
if(matriz[k][i]<10)
cout<<" "<<matriz[k][i];
else
cout<<" "<<matriz[k][i];
}
}
cin.get();cin.get();cin.get();
}
EJEMPLO 3:
/*
ALUMNO: FERNANDEZ ANCASI TERRY WILLIAMS
INGENIERIO: ROMAN MUNIVE WILDER
EJERCICIOS DEV-C++ DE LA MATRIZ:
           
          cout << "QUE TENGA BUEN DIA"; 
*/
using namespace std;
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<conio.h>
#include<math.h>
int const matriz=50;
void PDatos(int *Dim, float M[][matriz]);
void EDatos(int Dim, float M[][matriz]);
void CDet(int Dim, float M[][matriz]);

int main(void)
{
 int C,Dimension;
 float Matriz[matriz][matriz];
 PDatos(&Dimension,Matriz);
 cout<<"\n\n\n";
 printf("Calcula DETERMINANTE: ");
 cout<<"\n\n";
 EDatos(Dimension,Matriz);
 CDet(Dimension,Matriz);
 
 scanf("%d");
 return(0);
}

void PDatos(int *Dim,float M[][matriz])
{
 int A,B;
 cout << setw(61) << "ALUMNO: FERNANDEZ ANCASI  TERRY WILLIAMS" << endl << endl;
 cout << setw(55) << "INGENIERO: ROMAN MUNIVE WILDER" << endl << endl;
 cout<<"\n\n";
 cout<<setw(60)<<"CALCULA DETERMINANTE ESCALONANDO MATRIZ";
 cout<<"\n\n\n";
 cout<<"Introduce la dimension de la matriz: ";
 scanf("%d",&*Dim);
 cout<<"\n\n";
 printf(" INTRODUCIR CADA COMPONENTE DE LA MATRIZ: ");
 for(A=1;A<=*Dim;A++) 
 for(B=1;B<=*Dim;B++)
 {
 cout<<"\n";
 printf(" Termino A(%d,%d):",A,B); scanf("%f",&M[A][B]);}
 }
void EDatos(int Dim, float Mat[][matriz])
{
 int A,B;
 for(A=1;A<=Dim;A++)
 {
  for(B=1;B<=(Dim);B++)
   printf("%7.2f",Mat[A][B]);
   cout<<"\n";
 }
 }
void CDet(int Dim, float Mat[][matriz])
{
 int NCero,Col,C1,C2,A,NReg,Perm=0;
 float Pivote,V1,Det=1;

 for(Col=1;Col<=Dim;Col++){
  NCero=0;A=Col;
  while((NCero==0)&&(A<=Dim)){
   if((Mat[A][Col]>0.0000001)||((Mat[A][Col]<-0.0000001))){
    NCero=1;}
   else A++;}
  if (A>Dim) NReg=1;
  if (A!=Col) Perm++;
  Pivote=Mat[A][Col];
  for(C1=1;C1<=(Dim);C1++){
   V1=Mat[A][C1];
   Mat[A][C1]=Mat[Col][C1];
   Mat[Col][C1]=V1;}
  for(C2=Col+1;C2<=Dim;C2++){
   V1=Mat[C2][Col];
   for(C1=Col;C1<=(Dim);C1++){
    Mat[C2][C1]=Mat[C2][C1]-((V1/Pivote)*Mat[Col][C1]);}}
 }
    for(C2=1;C2<=Dim;C2++) Det=Det*Mat[C2][C2];
 A=Perm;
 if ((A%2)==1) Det=-Det;
 if (NReg==1) Det=0;
    printf("El determinante de la matriz es:   %f", Det);
    cout<<"\n\n";
    cout<<setw(50)<<"QUE TENGA UN BUEN DIA"<<endl;
}

No hay comentarios:

Publicar un comentario