ARREGLOS EN C++
INTERSECCION DE 2 ARREGLOS
#include<conio.h>
#include<iostream.h>
int w=0;
int interseccion(int m,int n,int A[],int B[]);
void main()
{
clrscr();
int m,n,i,j,k,A[50],B[50],I[50];
cout<<"\n ingrese la dimension de A :";cin>>m;
for(i=1;i<=m;i++)
{
cout<<"\n ingrese A["<<i<<"] : ";cin>>A[i];
}
cout<<"\n ingrese la dimension de B :";cin>>n;
for(j=1;j<=n;j++)
{
cout<<"\ningrese B["<<j<<"] : ";cin>>B[j];
}
interseccion(m,n,A,B);
//cout<<"\n"<<k;
for(k=1;k<=w;k++){
cout<<"\n"<<I[k];}
getch();
}
int interseccion(int m,int n, int A[],int B[])
{
int i,j,k,I[50];
k=0;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
if(A[i]==B[j])
{ w++;
k=k+1;
I[k]=A[i];
}
}
cout<<"\n"<<k;
}
MOSTRAR UNA MATRIZ
#include<iostream.h>
int w=0;
int interseccion(int m,int n,int A[],int B[]);
void main()
{
clrscr();
int m,n,i,j,k,A[50],B[50],I[50];
cout<<"\n ingrese la dimension de A :";cin>>m;
for(i=1;i<=m;i++)
{
cout<<"\n ingrese A["<<i<<"] : ";cin>>A[i];
}
cout<<"\n ingrese la dimension de B :";cin>>n;
for(j=1;j<=n;j++)
{
cout<<"\ningrese B["<<j<<"] : ";cin>>B[j];
}
interseccion(m,n,A,B);
//cout<<"\n"<<k;
for(k=1;k<=w;k++){
cout<<"\n"<<I[k];}
getch();
}
int interseccion(int m,int n, int A[],int B[])
{
int i,j,k,I[50];
k=0;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
if(A[i]==B[j])
{ w++;
k=k+1;
I[k]=A[i];
}
}
cout<<"\n"<<k;
}
MOSTRAR UNA MATRIZ
#include<conio.h>
#include<iostream.h>
#define filas 3
#define columnas 4
typedef Tmatriz[filas][columnas];
void leer(Tmatriz A);
void mostrar(Tmatriz A);
void main()
{
clrscr();
int i,j;
Tmatriz A;
leer(A);
mostrar(A);
getch();
}
void leer(Tmatriz A)
{
int i,j;
for(i=0;i<filas;i++)
for(j=0;j<columnas;j++)
{
cout<<"ingrese A["<<i<<"]["<<j<<"]: ";cin>>A[i][j];
}
}
void mostrar(Tmatriz A)
{
int i,j;
for(i=0;i<filas;i++)
{
for(j=0;j<columnas;j++)
{
cout<<" "<<A[i][j] ;
}
cout<<endl;
}
}
#include<iostream.h>
#define filas 3
#define columnas 4
typedef Tmatriz[filas][columnas];
void leer(Tmatriz A);
void mostrar(Tmatriz A);
void main()
{
clrscr();
int i,j;
Tmatriz A;
leer(A);
mostrar(A);
getch();
}
void leer(Tmatriz A)
{
int i,j;
for(i=0;i<filas;i++)
for(j=0;j<columnas;j++)
{
cout<<"ingrese A["<<i<<"]["<<j<<"]: ";cin>>A[i][j];
}
}
void mostrar(Tmatriz A)
{
int i,j;
for(i=0;i<filas;i++)
{
for(j=0;j<columnas;j++)
{
cout<<" "<<A[i][j] ;
}
cout<<endl;
}
}
MULTIPLICACION 2 MATRICES
#include<iostream.h>
#include<conio.h>
void main(){
int q,w,e,d,m,n,k,A[10][10],B[10][10],C[10][10];
cout<<"Ingrese el # de filas de A ";
cin>>q;
cout<<"Ingrese el # de columnas de A ";
cin>>w;
for(m=1;m<=q;m++){
for(n=1;n<=w;n++){
cin>>A[m][n];
}
}
cout<<"Ingrese el # de filas de B ";
cin>>e;
cout<<"Ingrese el # de columnas de B ";
cin>>d;
for(m=1;m<=e;m++){
for(n=1;n<=d;n++){
cin>>B[m][n];
}
}
if(w==e){
for(m=1;m<=q;m++){
for(n=1;n<=d;n++){
C[m][n]=0;
for(k=1;k<=e;k++){
C[m][n]=C[m][n]+A[m][k]*B[k][n];
}
cout<<C[m][n]<<" ";
}
cout<<endl;
}
}
else
cout<<"Error ";
getch();
}
#include<conio.h>
void main(){
int q,w,e,d,m,n,k,A[10][10],B[10][10],C[10][10];
cout<<"Ingrese el # de filas de A ";
cin>>q;
cout<<"Ingrese el # de columnas de A ";
cin>>w;
for(m=1;m<=q;m++){
for(n=1;n<=w;n++){
cin>>A[m][n];
}
}
cout<<"Ingrese el # de filas de B ";
cin>>e;
cout<<"Ingrese el # de columnas de B ";
cin>>d;
for(m=1;m<=e;m++){
for(n=1;n<=d;n++){
cin>>B[m][n];
}
}
if(w==e){
for(m=1;m<=q;m++){
for(n=1;n<=d;n++){
C[m][n]=0;
for(k=1;k<=e;k++){
C[m][n]=C[m][n]+A[m][k]*B[k][n];
}
cout<<C[m][n]<<" ";
}
cout<<endl;
}
}
else
cout<<"Error ";
getch();
}
SUMA DE MATRICES
#include<iostream.h>
#include<conio.h>
int m,n,i,j;
int A[30][30],B[30][30],S[30][30];
void sumarmatrices(int n,int m,int A[30][30],int B[30][30],int S[30][30]);
void main()
{
int m,n,p,q;
clrscr();
cout<<"\nINGRESE EL NUMERO DE FILAS DE A: ";
cin>>m;
cout<<"\nINGRESE EL NUMERO DE COLUMNAS DE A:";
cin>>n;
cout<<"\nINGRESE EL NUMERO DE FILAS DE B:";
cin>>p;
cout<<"\nINGRESE EL NUMERO DE COLUMNAS DE B:";
cin>>q;
if(m==p && n==q)
{
cout<<"\n ****ingrese los elementos ****";
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
cout<<"\nmatriz["<<i<<"]"<<"["<<j<<"]:";
cin>>A[i][j];
}
cout<<"\n ****ingrese los elementos B ****";
for(i=1;i<=p;i++)
for(j=1;j<=q;j++)
{
cout<<"\nmatriz["<<i<<"]"<<"["<<j<<"]:";
cin>>B[i][j];
}
}
else
cout<<"\nno se puede realizar la suma";
sumarmatrices(n,m,A,B,S);
cout<<"\nla suma de las matrices es:"<<endl;
for(i=1;i<=m;i++){
for(j=1;j<=n;j++)
{
cout<<" "<<S[i][j];
}
cout<<endl;
}
getch();
}
void sumarmatrices(int n,int m,int A[30][30],int B[30][30],int S[30][30])
{
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
S[i][j]=A[i][j]+B[i][j];
}
}
#include<conio.h>
int m,n,i,j;
int A[30][30],B[30][30],S[30][30];
void sumarmatrices(int n,int m,int A[30][30],int B[30][30],int S[30][30]);
void main()
{
int m,n,p,q;
clrscr();
cout<<"\nINGRESE EL NUMERO DE FILAS DE A: ";
cin>>m;
cout<<"\nINGRESE EL NUMERO DE COLUMNAS DE A:";
cin>>n;
cout<<"\nINGRESE EL NUMERO DE FILAS DE B:";
cin>>p;
cout<<"\nINGRESE EL NUMERO DE COLUMNAS DE B:";
cin>>q;
if(m==p && n==q)
{
cout<<"\n ****ingrese los elementos ****";
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
cout<<"\nmatriz["<<i<<"]"<<"["<<j<<"]:";
cin>>A[i][j];
}
cout<<"\n ****ingrese los elementos B ****";
for(i=1;i<=p;i++)
for(j=1;j<=q;j++)
{
cout<<"\nmatriz["<<i<<"]"<<"["<<j<<"]:";
cin>>B[i][j];
}
}
else
cout<<"\nno se puede realizar la suma";
sumarmatrices(n,m,A,B,S);
cout<<"\nla suma de las matrices es:"<<endl;
for(i=1;i<=m;i++){
for(j=1;j<=n;j++)
{
cout<<" "<<S[i][j];
}
cout<<endl;
}
getch();
}
void sumarmatrices(int n,int m,int A[30][30],int B[30][30],int S[30][30])
{
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
S[i][j]=A[i][j]+B[i][j];
}
}
No hay comentarios:
Publicar un comentario