Multiplicación de Matrices
Codigo en C++ Cuadros Magicos y Triangulos de Pascal
#include <iostream>
#include"stdio.h"
#include"stdlib.h"
#include"iostream"
using namespace std;
# define nestor 9
# define OP 13
void rotativa()
{
int M[10][10];
int d,r,i,j,a=0;
int o1[10][10],sum;
cout<<"\nLa Dimension de la matriz cuadrada <=10\n";
d=nestor;
sum=0;
for(r=1;r<=d;r++)
for(i=1;i<=d;i++)
{
sum=sum+1;
M[r][i]=sum;
}
for(r=1;r<=d;r++)
for(i=1;i<=d;i++)
o1[r][i]=M[d+1-r][d+1-i];
cout<<"\n\n";
for(r=1;r<=d;r++)
{
for(i=1;i<=d;i++)
printf("%5d",o1[r][i]);
cout<<"\n";
a=a+d;
}
for(r=1;r<=d;r++)
{
for(j=1;j<=d;j++)printf(" ");
for(i=1;i<=d;i++)
{
printf("%5d",M[r][i]);
}
cout<<"\n";
}
}
void pascal1()
{
int x,y,dimen;
int mat[20][20],fil=2,col=2;
cout<<"\nTRIANGULO DE PASCAL 1";
printf("\nLa dimencion:es de%d",nestor);
cout<<"\n";
dimen=nestor;
for(x=1;x<=dimen;x++)
{
mat[x][1]=1;
mat[x][x]=1;
}
for(x=3;x<=dimen;x++)
{
for(y=2;y<=x-1;y++)
mat[x][y]=mat[x-1][y]+mat[x-1][y-1];
}
for(x=1;x<=dimen;x++)
{
for(y=1;y<=x;y++)
{
//gotoxy(col+20,fil+5);
printf("%d",mat[x][y]);
cout<<"\t";
col=col+5;
}
fil=fil+1;
cout<<"\n";
col=2;
}
}
int pascal2()
{
int x,y,dimen;
int mat[20][20],fil=2,col=2;
cout<<"\nTRIANGULO DE PASCAL 2";
cout<<"\nDimencion es"<<nestor;
cout<<"\n";
dimen =nestor;
for(x=1;x<=dimen;x++)
{
mat[x][1]=1;
mat[x][x]=1;
}
for(x=3;x<=dimen;x++)
{
for(y=2;y<=x-1;y++)
mat[x][y]=mat[x-1][y]+mat[x-1][y-1];
}
for(x=1;x<=dimen;x++)
{
for(y=1;y<=x;y++)
{
cout<<"\t"<<mat[x][y];
col=col+5;
}
fil=fil+1;
cout<<"\n";
col=2;
}
return 0;
}
void pascal3()
{
int M[20][20],x,y,d;
cout<<"\nTRIANGULO DE PASCAL # 3";
cout<<"\nDimension de la matriz:"<<nestor;
cout<<"\n";
d=nestor;
for(x=1;x<=d;x++)
for (y=1;y<=d;y++)
M[x][y]=0;
for (x=1;x<=d;x++)
M[1][x]=M[x][d+1-x]=1;
for (y=d-2;y>=1;y--)
for (x=2;x<=d-y;x++)
M[x][y]=M[x-1][y+1]+M[x][y+1];
for(x=1;x<=d;x++){
cout<<"\n\t";
for (y=1;y<=d;y++){
if(M[x][y]==0)
cout<<" ";
else
if (M[x][y]<=9)
cout<<" "<<M[x][y];
else
cout<<" "<<M[x][y];
}
}
}
void pascal4()
{
int M[20][20],x,y,d;
cout<<"\nTRIANGULO DE PASCAL 4";
cout<<"\nDimension de la matriz:"<<nestor;
cout<<"\n";
d=nestor;
for(x=1;x<=d;x++)
for (y=1;y<=d;y++)
M[x][y]=0;
for (x=1;x<=d;x++)
M[x][d]=M[x][d+1-x]=1;
for (x=3;x<=d;x++)
for (y=d-1;y>=d+2-x;y--)
M[x][y]=M[x-1][y+1]+M[x-1][y];
for (x=1;x<=d;x++) {
for (y=1;y<=d;y++) {
if(M[x][y]==0)
cout<<" ";
else
if (M[x][y]<=9)
cout<<" "<<M[x][y];
else
cout<<" "<<M[x][y];
}
cout<<"\n";
}
}
void pascal5()
{
int M[20][20];
int s,r,i,j,d,a=0,o1[10][10],sum,x,y;
cout<<"\nTRIANGULO DE PASCAL # 5";
cout<<"\nDimension de la matriz:"<<nestor;
cout<<"\n";
d=nestor;
for(x=1;x<=d;x++)
for (y=1;y<=d;y++)
M[x][y]=0;
for (x=1;x<=d;x++)
M[1][x]=M[x][d+1-x]=1;
for (y=d-2;y>=1;y--)
for (x=2;x<=d-y;x++)
M[x][y]=M[x-1][y+1]+M[x][y+1];
/*
for(x=1;x<=d;x++)
{
//cout<<"\n";
for (y=1;y<=d;y++)
{ if(M[x][y]==0)
cout<<"";
else
if (M[x][y]<=9)
{
//cout<<""<<M[x][y];
}
else
cout<<M[x][y];
}
}
*/
//rotar la matriz
for(r=1;r<=d;r++)
for(i=1;i<=d;i++)
o1[r][i]=M[d+1-r][d+1-i];
cout<<"\n";
for(r=1;r<=d;r++)
{
for(i=1;i<=d;i++)
{
if (o1[r][i]==0)
cout<<" ";
else
printf("%3d",o1[r][i]);
}
cout<<"\n";
a=a+d;
}
}
void pascal6()
{
int M[20][20];
int x,y,d;
cout<<"\nDimension de la matriz:";
d=nestor;
for(x=1;x<=d;x++)
for(y=1;y<=d;y++)
M[x][y]=0;
for(x=1;x<=d;x++)
M[d][x]=M[x][x]=1;
for (y=d-2;y>=1;y--)
for (x=d-1;x>=y+1;x--)
M[x][y]=M[x+1][y+1]+M[x][y+1];
for(x=1;x<=d;x++){
cout<<"\n\t";
for(y=1;y<=d;y++)
{
if(M[x][y]==0)
cout<<" ";
else
cout<<" "<<M[x][y];
}
}
}
int main()
{
int X,F,C,Y;
int MAT[20][20];
do
{
//system("cls");
//textcolor(15);
//textbackground(1);
cout<<" MATRIZ MAGICA TRIANGULO DE PASCAL";
cout<<" \n------------------------------ ------------------";
cout<<"\n";
cout<<"1. CUADRO MAGICO # I 2. CUADRO MAGICO # V 9. PASCAL I 13.PASCA V \n";
cout<<"3. CUADRO MAGICO # II 4. CUADRO MAGICO # VI 10. PASCAL II 14.PASCAL VI \n";
cout<<"5. CUADRO MAGICO # III 6. CUADRO MAGICO # VII 11. PASCAL III 15.ROTATIVA \n";
cout<<"7. CUADRO MAGICO # III 8. CUADRO MAGICO # VII 12. PASCAL IV 16.ESPEJO \n";
cout<<" \n";
cout<<" DIGITE OPCION: "<<OP;
//cin>>OP;
//OP=1;
switch(OP)
{
case 1:{
//system("cls");
F=1;
C=(nestor+1)/2;
for(X=1;X<=nestor*nestor;X++)
{
MAT[F][C]=X;
if(X%nestor==0)
{
F++;
}
else
{
F--;
C++;
if(F<1) F=nestor;
if(C>nestor) C=1;
}
}
cout<<" CUADRO MAGICO # 1:";
cout<<"\n------------------------------------------";
cout<<"\n";
for(X=1;X<=nestor;X++)
{
for(Y=1;Y<=nestor;Y++)
{
cout<<" "<<MAT[X][Y];
}
cout<<" \n";
}
return 0;
break;
}
case 2:{
cout<<"\nDimension de la matriz:"<<nestor;
F=(nestor+1)/2;
C=nestor;
for(X=1;X<=nestor*nestor;X++)
{
MAT[F][C]=X;
if(X%nestor==0)
{
C--;
}
else
{
F--;
C++;
if(F<1) F=nestor;
if(C>nestor) C=1;
}
}
cout<<" CUADRO MAGICO # 2:\n";
cout<<" \n";
for(X=1;X<=nestor;X++)
{
for(Y=1;Y<=nestor;Y++)
{
cout<<" "<<MAT[X][Y];
}
cout<<" \n";
}
break;
}
case 3:{
cout<<" \n";
cout<<"Dimension de la matriz:"<<nestor;
//cin>>nestor;
cout<<" \n\n";
F=(nestor+1)/2;
C=nestor;
for(X=1;X<=nestor*nestor;X++)
{
MAT[F][C]=X;
if(X%nestor==0)
{
C--;
}
else
{
F++;
C++;
if(F>nestor) F=1;
if(C>nestor) C=1;
}
}
cout<<" CUADRO MAGICO # 3:\n";
for(X=1;X<=nestor;X++)
{
for(Y=1;Y<=nestor;Y++)
{
cout<<" "<<MAT[X][Y];
}
cout<<" \n";
}
break;
}
case 4:{
cout<<" \n";
cout<<"Dimension de la matriz:"<<nestor;
F=nestor;
C=(nestor+1)/2;
for(X=1;X<=nestor*nestor;X++)
{
MAT[F][C]=X;
if(X%nestor==0)
{
F--;
}
else
{
F++;
C++;
if(F>nestor) F=1;
if(C>nestor) C=1;
}
}
cout<<" CUADRO MAGICO # 4:\n";
for(X=1;X<=nestor;X++)
{
for(Y=1;Y<=nestor;Y++)
{
cout<<" "<<MAT[X][Y];
}
cout<<" \n";
}
//getch();
break;
}
case 5:{
cout<<" \n";
cout<<"Dimension de la matriz:"<<nestor;
cout<<" \n\n";
F=nestor;
C=(nestor+1)/2;
for(X=1;X<=nestor*nestor;X++)
{
MAT[F][C]=X;
if(X%nestor==0)
{
F--;
}
else
{
F++;
C--;
if(F>nestor) F=1;
if(C<1) C=nestor;
}
}
cout<<" CUADRO MAGICO # 5 :\n";
for(X=1;X<=nestor;X++)
{
for(Y=1;Y<=nestor;Y++)
{
cout<<" "<<MAT[X][Y];
}
cout<<" \n";
}
//getch();
break;
}
case 6:{
//system("cls");
//system("Color b5");
cout<<" \n";
cout<<"Dimension de la matriz:"<<nestor;
// cin>>nestor;
F=(nestor+1)/2;
C=1;
for(X=1;X<=nestor*nestor;X++)
{
MAT[F][C]=X;
if(X%nestor==0)
{
C++;
}
else
{
F++;
C--;
if(F>nestor) F=1;
if(C<1) C=nestor;
}
}
cout<<" CUADRO MAGICO # 6 :\n";
for(X=1;X<=nestor;X++)
{
for(Y=1;Y<=nestor;Y++)
{
cout<<" "<<MAT[X][Y];
}
cout<<" \n";
}
// getch();
break;
}
case 7:{
cout<<" \n";
cout<<"Dimension de la matriz:"<<nestor;
//cin>>nestor;
F=(nestor+1)/2;
C=1;
for(X=1;X<=nestor*nestor;X++)
{
MAT[F][C]=X;
if(X%nestor==0)
{
C++;
}
else
{
F--;
C--;
if(F<1) F=nestor;
if(C<1) C=nestor;
}
}
cout<<" \n";
cout<<" CUADRO MAGICO # 7 \n";
for(X=1;X<=nestor;X++)
{
for(Y=1;Y<=nestor;Y++)
{
cout<<" "<<MAT[X][Y];
}
cout<<" \n";
}
// getch();
break;
}
case 8:{
cout<<" \n";
cout<<"Dimension de la matriz:"<<nestor;
//cin>>nestor;
F=1;
C=(nestor+1)/2;
for(X=1;X<=nestor*nestor;X++)
{
MAT[F][C]=X;
if(X%nestor==0)
{
F++;
}
else
{
F--;
C--;
if(F<1) F=nestor;
if(C<1) C=nestor;
}
}
cout<<"CUADRO MAGICO # 8:\n";
cout<<" \n\n";
for(X=1;X<=nestor;X++)
{for(Y=1;Y<=nestor;Y++)
{cout<<" "<<MAT[X][Y];}
cout<<" \n";}break;}
case 9:{pascal1();break;}
case 10:{pascal2();break;}
case 11:{pascal3();break;}
case 12:{pascal4();break;}
case 13:{pascal5();break;}//case 13:{pascal5();break;}
case 14:{pascal6();break;}
case 15:{rotativa();break;}
}
return 0;
} while(OP!=0);
return 0;
}
No hay comentarios:
Publicar un comentario