Está en la página 1de 5

#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 &auxmat riz2){ 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("\n\t\t1. Leer Orden de la Matriz\n"); printf("\t\t2. Leer matriz 1\n"); printf("\t\t3. Leer Matriz 2\n"); printf("\t\t4. Presentar MAtriz1\n"); printf("\t\t5. Presentar Matriz2\n"); printf("\t\t6. Numeros Pares e Impares\n"); printf("\t\t7. Numeros Primos\n"); printf("\t\t8. Diagonal Principal\n"); printf("\t\t9. Diagonal secundaria\n"); printf("\t\t10. Suma de matrices\n"); printf("\t\t11. Multiplicacion de matrices\n"); printf("\t\t12. Sumatoria terminos\n"); printf("\t\t13. Promedio de los terminos\n"); printf("\t\t14. Salir\n"); printf("=============================================================\n"); printf("=== W I L L I A M R O D R I G U E Z 2001 . ===\n"); printf("=============================================================\n"); printf("\n\nPor 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("\n\a\n\n\n\n\n\n Copy Right 2001 by William Rodriguez."); textbackground(BLUE); textcolor(YELLOW); cprintf("\n\a\n\n That's all fuck's friends!! "); return 0; }

También podría gustarte