MATRICES
NECESITO UN PROGRAMA QUE CALCULE MATRICES , SI HAY ALGUIEN QUE ME PUEDA AYUDAR GRACIAS!!!!!!
ahi en las respuestas para ale se encuentran dos codigos de matrices, los consegui de otra page donde tambien compartimos conocimiento
Código fuente de un programa de operaciones con matrices, lee 2 matrices de NxN, las visualiza en forma logica (Como Matriz), determina los numeros pares, impares, primos, la diagonal principal y secundaria de cada una de las matrices, las suma y las multiplica, todo esto recurriendo a funciones y en pocas lineas de codigo. Y por si fuera poco determina la sumatoria y el promedio de los terminos de esta.
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
const maxfil = 100, maxcol = 100;
typedef int tipomatriz[maxfil][maxcol];
void leerorden(int &auxN, int &auxM){
clrscr();
do{
printf("Por favor digite el maximo de filas : ");
scanf("%d",&auxN);
}while(auxN>100);
printf("n");
do{
printf("Por favor digite el maximo de columnas : ");
scanf("%d",&auxM);
}while(auxM>100);
}
void leermatriz(int auxN, int auxM, tipomatriz &auxMATRIZ){
int i,j,columna;
clrscr();
printf("POR FAVOR DIGITE LOS DATOS DE LA MATRIZ DE ORDEN [%dx%d]",auxN,auxM);
for(i=0;i<auxN;i++){
columna = 5;
for(j=0;j<auxM;j++){
gotoxy(columna,i+3);
scanf("%d",&auxMATRIZ[i][j]);
columna = columna + 5;
}
}
}
void escribirmatriz(int auxN, int auxM, tipomatriz auxMATRIZ){
int i,j,columna;
clrscr();
printf("LOS DATOS DE LA MATRIZ DE ORDEN [%dx%d] SON ",auxN,auxM);
for(i=0;i<auxN;i++){
columna = 5;
for(j=0;j<auxM;j++){
gotoxy(columna,i+3);
printf("%d",auxMATRIZ[i][j]);
columna = columna + 5;
}
}
}
int analizarpar(int numero){
int residuo;
residuo = numero % 2;
return residuo==0;
}
void parimparmatriz(int auxN, int auxM, tipomatriz auxMATRIZ){
int i,j,columna;
clrscr();
printf("NUMEROS PARES E IMPARES DE LA MATRIZ DE ORDEN [%dx%d] SON ",auxN,auxM);
for(i=0;i<auxN;i++){
columna = 5;
for(j=0;j<auxM;j++){
gotoxy(columna,i+3);
if(analizarpar(auxMATRIZ[i][j]))
textcolor(RED);
else
textcolor(GREEN);
cprintf("%d",auxMATRIZ[i][j]);
columna = columna + 5;
}
}
}
int primo(int numero){
int divisionesexactas,divisor;
divisionesexactas=0;
for(divisor=1;divisor<=abs(numero);divisor++){
if(numero%divisor==0){
divisionesexactas++;
}
}
return divisionesexactas<=2;
}
void numerosprimos(int auxN, int auxM, tipomatriz auxMATRIZ){
int i,j,columna;
clrscr();
printf("NUMEROS PRIMOS DE LA MATRIZ DE ORDEN [%dx%d] SON ",auxN,auxM);
for(i=0;i<auxN;i++){
columna = 5;
for(j=0;j<auxM;j++){
gotoxy(columna,i+3);
if(primo(auxMATRIZ[i][j]))
textcolor(YELLOW);
else
textcolor(MAGENTA);
cprintf("%d",auxMATRIZ[i][j]);
columna = columna + 5;
}
}
}
void diagonalppal(int auxN, int auxM, tipomatriz auxMATRIZ){
int i,j,columna;
clrscr();
printf("LA DIAGONAL PRINCIPAL DE LA MATRIZ DE ORDEN [%dx%d] ES ",auxN,auxM);
for(i=0;i<auxN;i++){
columna = 5;
for(j=0;j<auxM;j++){
gotoxy(columna,i+3);
if(i==j)
textcolor(CYAN);
else
textcolor(BLUE);
cprintf("%d",auxMATRIZ[i][j]);
columna = columna + 5;
}
}
}
void diagonalsecn(int auxN, int auxM, tipomatriz auxMATRIZ){
int i,j,columna;
clrscr();
printf("LA DIAGONAL SECUNDARIS DE LA MATRIZ DE ORDEN [%dx%d] ES ",auxN,auxM);
for(i=0;i<auxN;i++){
columna = 5;
for(j=0;j<auxM;j++){
gotoxy(columna,i+3);
if(i+j==auxM-1)
textcolor(CYAN);
else
textcolor(BLUE);
cprintf("%d",auxMATRIZ[i][j]);
columna = columna + 5;
}
}
}
void sumamatrices(int auxN, int auxM, tipomatriz &auxmatriz1, tipomatriz &auxmatriz2){
int i,j,columna; tipomatriz auxmatriz3;
clrscr();
for (i=0;i<auxN;i++){
columna = 5;
for (j=0;j<auxM;j++){
auxmatriz3[i][j]=(auxmatriz1[i][j]+auxmatriz2[i][j]);
gotoxy(columna,i+3);
printf("%d",auxmatriz3[i][j]);
columna+=5;}}
}
void multimatrices(int auxN,int auxM,tipomatriz auxmatriz1,tipomatriz auxmatriz2){
int i,j,columna; tipomatriz auxmatriz3;
clrscr();
if (auxN==auxM){
for (i=0;i<auxN;i++){
columna=5;
for (j=0;j<auxM;j++){
auxmatriz3[i][j]=(auxmatriz1[i][j]*auxmatriz2[j][i]);
gotoxy(columna,i+3);
printf("%d",auxmatriz3[i][j]);
columna+=5;}}}
else printf("nLas matrices no son cuadradas!!");
}
void sumaterm(int auxN,int auxM,tipomatriz auxmatriz){
int i,j,sumat=0;
clrscr();
for (i=0;i<auxN;i++)
for (j=0;j<auxM;j++)
sumat+=auxmatriz[i][j];
printf("La sumatoria de los terminos de la matriz es: %d .",sumat);
}
void promedio(int auxN,int auxM,tipomatriz auxmatriz){
float i,j,sumat=0;
float prom=0;
clrscr();
for (i=0;i<auxN;i++)
for (j=0;j<auxM;j++)
sumat+=auxmatriz[i][j];
prom=(sumat/(auxN*auxM));
printf("El promedio de los terminos de la matriz es: %.2f .",prom);
}
main(){
int n,m,opcion;
tipomatriz matriz1,matriz2,matriz3;
do{
textcolor(WHITE);
clrscr();
printf("=============================================================n");
printf("=== M A T R I X . ===n");
printf("=============================================================n");
printf("ntt1. Leer Orden de la Matrizn");
printf("tt2. Leer matriz 1n");
printf("tt3. Leer Matriz 2n");
printf("tt4. Presentar MAtriz1n");
printf("tt5. Presentar Matriz2n");
printf("tt6. Numeros Pares e Imparesn");
printf("tt7. Numeros Primosn");
printf("tt8. Diagonal Principaln");
printf("tt9. Diagonal secundarian");
printf("tt10. Suma de matricesn");
printf("tt11. Multiplicacion de matricesn");
printf("tt12. Sumatoria terminosn");
printf("tt13. Promedio de los terminosn");
printf("tt14. Salirn");
printf("=============================================================n");
printf("=== W I L L I A M R O D R I G U E Z 2001 . ===n");
printf("=============================================================n");
printf("nnPor favor escoga la opcion deseada: ");
scanf("%d",&opcion);
switch(opcion){
case 1 : leerorden(n,m); break;
case 2 : leermatriz(n,m,matriz1);break;
case 3 : leermatriz(n,m,matriz2);break;
case 4 : escribirmatriz(n,m,matriz1); getch();break;
case 5 : escribirmatriz(n,m,matriz2); getch();break;
case 6 : parimparmatriz(n,m,matriz1);getch();
parimparmatriz(n,m,matriz2);
getch();break;
case 7 : numerosprimos(n,m,matriz1); getch();
numerosprimos(n,m,matriz2);getch();
break;
case 8 : diagonalppal(n,m,matriz1); getch();
diagonalppal(n,m,matriz2); getch();
break;
case 9: diagonalsecn(n,m,matriz1); getch();
diagonalsecn(n,m,matriz2); getch();
break;
case 10: sumamatrices(n,m,matriz1,matriz2);getch();
break;
case 11: multimatrices(n,m,matriz1,matriz2);getch();
break;
case 12: sumaterm(n,m,matriz1);getch();
sumaterm(n,m,matriz2);getch();
break;
case 13:promedio(n,m,matriz1);getch();
promedio(n,m,matriz2);getch();
break;
}
}while(opcion!=14);
clrscr();
textbackground(WHITE);
textcolor(BLACK);
cprintf("nannnnnn Copy Right 2001 by William Rodriguez.");
textbackground(BLUE);
textcolor(YELLOW);
cprintf("nann That's all fuck's friends!! ");
return 0;
}
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
const maxfil = 100, maxcol = 100;
typedef int tipomatriz[maxfil][maxcol];
void leerorden(int &auxN, int &auxM){
clrscr();
do{
printf("Por favor digite el maximo de filas : ");
scanf("%d",&auxN);
}while(auxN>100);
printf("n");
do{
printf("Por favor digite el maximo de columnas : ");
scanf("%d",&auxM);
}while(auxM>100);
}
void leermatriz(int auxN, int auxM, tipomatriz &auxMATRIZ){
int i,j,columna;
clrscr();
printf("POR FAVOR DIGITE LOS DATOS DE LA MATRIZ DE ORDEN [%dx%d]",auxN,auxM);
for(i=0;i<auxN;i++){
columna = 5;
for(j=0;j<auxM;j++){
gotoxy(columna,i+3);
scanf("%d",&auxMATRIZ[i][j]);
columna = columna + 5;
}
}
}
void escribirmatriz(int auxN, int auxM, tipomatriz auxMATRIZ){
int i,j,columna;
clrscr();
printf("LOS DATOS DE LA MATRIZ DE ORDEN [%dx%d] SON ",auxN,auxM);
for(i=0;i<auxN;i++){
columna = 5;
for(j=0;j<auxM;j++){
gotoxy(columna,i+3);
printf("%d",auxMATRIZ[i][j]);
columna = columna + 5;
}
}
}
int analizarpar(int numero){
int residuo;
residuo = numero % 2;
return residuo==0;
}
void parimparmatriz(int auxN, int auxM, tipomatriz auxMATRIZ){
int i,j,columna;
clrscr();
printf("NUMEROS PARES E IMPARES DE LA MATRIZ DE ORDEN [%dx%d] SON ",auxN,auxM);
for(i=0;i<auxN;i++){
columna = 5;
for(j=0;j<auxM;j++){
gotoxy(columna,i+3);
if(analizarpar(auxMATRIZ[i][j]))
textcolor(RED);
else
textcolor(GREEN);
cprintf("%d",auxMATRIZ[i][j]);
columna = columna + 5;
}
}
}
int primo(int numero){
int divisionesexactas,divisor;
divisionesexactas=0;
for(divisor=1;divisor<=abs(numero);divisor++){
if(numero%divisor==0){
divisionesexactas++;
}
}
return divisionesexactas<=2;
}
void numerosprimos(int auxN, int auxM, tipomatriz auxMATRIZ){
int i,j,columna;
clrscr();
printf("NUMEROS PRIMOS DE LA MATRIZ DE ORDEN [%dx%d] SON ",auxN,auxM);
for(i=0;i<auxN;i++){
columna = 5;
for(j=0;j<auxM;j++){
gotoxy(columna,i+3);
if(primo(auxMATRIZ[i][j]))
textcolor(YELLOW);
else
textcolor(MAGENTA);
cprintf("%d",auxMATRIZ[i][j]);
columna = columna + 5;
}
}
}
void diagonalppal(int auxN, int auxM, tipomatriz auxMATRIZ){
int i,j,columna;
clrscr();
printf("LA DIAGONAL PRINCIPAL DE LA MATRIZ DE ORDEN [%dx%d] ES ",auxN,auxM);
for(i=0;i<auxN;i++){
columna = 5;
for(j=0;j<auxM;j++){
gotoxy(columna,i+3);
if(i==j)
textcolor(CYAN);
else
textcolor(BLUE);
cprintf("%d",auxMATRIZ[i][j]);
columna = columna + 5;
}
}
}
void diagonalsecn(int auxN, int auxM, tipomatriz auxMATRIZ){
int i,j,columna;
clrscr();
printf("LA DIAGONAL SECUNDARIS DE LA MATRIZ DE ORDEN [%dx%d] ES ",auxN,auxM);
for(i=0;i<auxN;i++){
columna = 5;
for(j=0;j<auxM;j++){
gotoxy(columna,i+3);
if(i+j==auxM-1)
textcolor(CYAN);
else
textcolor(BLUE);
cprintf("%d",auxMATRIZ[i][j]);
columna = columna + 5;
}
}
}
void sumamatrices(int auxN, int auxM, tipomatriz &auxmatriz1, tipomatriz &auxmatriz2){
int i,j,columna; tipomatriz auxmatriz3;
clrscr();
for (i=0;i<auxN;i++){
columna = 5;
for (j=0;j<auxM;j++){
auxmatriz3[i][j]=(auxmatriz1[i][j]+auxmatriz2[i][j]);
gotoxy(columna,i+3);
printf("%d",auxmatriz3[i][j]);
columna+=5;}}
}
void multimatrices(int auxN,int auxM,tipomatriz auxmatriz1,tipomatriz auxmatriz2){
int i,j,columna; tipomatriz auxmatriz3;
clrscr();
if (auxN==auxM){
for (i=0;i<auxN;i++){
columna=5;
for (j=0;j<auxM;j++){
auxmatriz3[i][j]=(auxmatriz1[i][j]*auxmatriz2[j][i]);
gotoxy(columna,i+3);
printf("%d",auxmatriz3[i][j]);
columna+=5;}}}
else printf("nLas matrices no son cuadradas!!");
}
void sumaterm(int auxN,int auxM,tipomatriz auxmatriz){
int i,j,sumat=0;
clrscr();
for (i=0;i<auxN;i++)
for (j=0;j<auxM;j++)
sumat+=auxmatriz[i][j];
printf("La sumatoria de los terminos de la matriz es: %d .",sumat);
}
void promedio(int auxN,int auxM,tipomatriz auxmatriz){
float i,j,sumat=0;
float prom=0;
clrscr();
for (i=0;i<auxN;i++)
for (j=0;j<auxM;j++)
sumat+=auxmatriz[i][j];
prom=(sumat/(auxN*auxM));
printf("El promedio de los terminos de la matriz es: %.2f .",prom);
}
main(){
int n,m,opcion;
tipomatriz matriz1,matriz2,matriz3;
do{
textcolor(WHITE);
clrscr();
printf("=============================================================n");
printf("=== M A T R I X . ===n");
printf("=============================================================n");
printf("ntt1. Leer Orden de la Matrizn");
printf("tt2. Leer matriz 1n");
printf("tt3. Leer Matriz 2n");
printf("tt4. Presentar MAtriz1n");
printf("tt5. Presentar Matriz2n");
printf("tt6. Numeros Pares e Imparesn");
printf("tt7. Numeros Primosn");
printf("tt8. Diagonal Principaln");
printf("tt9. Diagonal secundarian");
printf("tt10. Suma de matricesn");
printf("tt11. Multiplicacion de matricesn");
printf("tt12. Sumatoria terminosn");
printf("tt13. Promedio de los terminosn");
printf("tt14. Salirn");
printf("=============================================================n");
printf("=== W I L L I A M R O D R I G U E Z 2001 . ===n");
printf("=============================================================n");
printf("nnPor favor escoga la opcion deseada: ");
scanf("%d",&opcion);
switch(opcion){
case 1 : leerorden(n,m); break;
case 2 : leermatriz(n,m,matriz1);break;
case 3 : leermatriz(n,m,matriz2);break;
case 4 : escribirmatriz(n,m,matriz1); getch();break;
case 5 : escribirmatriz(n,m,matriz2); getch();break;
case 6 : parimparmatriz(n,m,matriz1);getch();
parimparmatriz(n,m,matriz2);
getch();break;
case 7 : numerosprimos(n,m,matriz1); getch();
numerosprimos(n,m,matriz2);getch();
break;
case 8 : diagonalppal(n,m,matriz1); getch();
diagonalppal(n,m,matriz2); getch();
break;
case 9: diagonalsecn(n,m,matriz1); getch();
diagonalsecn(n,m,matriz2); getch();
break;
case 10: sumamatrices(n,m,matriz1,matriz2);getch();
break;
case 11: multimatrices(n,m,matriz1,matriz2);getch();
break;
case 12: sumaterm(n,m,matriz1);getch();
sumaterm(n,m,matriz2);getch();
break;
case 13:promedio(n,m,matriz1);getch();
promedio(n,m,matriz2);getch();
break;
}
}while(opcion!=14);
clrscr();
textbackground(WHITE);
textcolor(BLACK);
cprintf("nannnnnn Copy Right 2001 by William Rodriguez.");
textbackground(BLUE);
textcolor(YELLOW);
cprintf("nann That's all fuck's friends!! ");
return 0;
}
