miguelmarve

mis operaciones de matrices

Oct 29th, 2012
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. http://estructuradatos.wordpress.com/2007/12/19/mayor-y-menor-matriz/
  2. #include <iostream.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5.  
  6. void MayorMenor (int matriz[20][20],int nivel);
  7. int matriz[20][20];
  8.  
  9. main(){
  10.  
  11. //int matriz[10][10];
  12. int i=0,j=0;
  13. int elemento = 0;
  14.  
  15. int nivel=0;
  16. printf(“Ingresa el nivel de la matriz: “);
  17. scanf(“%d”,&nivel);
  18.  
  19. //ingresar elementos
  20. printf(“\n”);
  21. for(i=0;i<nivel;i++){
  22. for(j=0;j<nivel;j++){
  23. printf(“Ingesa elemento[%d][%d]: “,i,j);
  24. scanf(“%d”,&elemento);
  25. matriz[i][j] = elemento;
  26. }
  27. }
  28.  
  29. //presentar elementos
  30. printf(“\nMatriz ingresada fue: \n”);
  31. for(i=0;i<nivel;i++){
  32. for(j=0;j<nivel;j++){
  33. printf(“%d\t”,matriz[i][j]);
  34. }
  35. printf(“\n”);
  36. }
  37. //Presentar mayor y menor
  38. MayorMenor(matriz,nivel);
  39.  
  40. system(“PAUSE”);
  41. return 0;
  42. }
  43.  
  44. void MayorMenor (int matriz[20][20],int nivel)
  45. {
  46. int i = 0,j = 0;
  47. int mayor = matriz[0][0];
  48. int menor = matriz[0][0];
  49. int elemento = 0;
  50.  
  51. for(i=0;i<nivel;i++){
  52. for(j=0;j<nivel;j++){
  53. elemento = matriz[i][j];
  54. if(elemento>mayor)
  55. {
  56. mayor=elemento;
  57. }
  58. if(elemento<menor)
  59. {
  60. menor=elemento;
  61. }
  62. }
  63. }
  64.  
  65. printf(“\nElemnto mayor: %d”,mayor);
  66. printf(“\nElemnto menor: %d\n\n”,menor);
  67. }
  68. http://waldestrand.wordpress.com/2008/06/30/multiplicacion-de-dos-matrices-en-c/
  69.  
  70. #include<stdio.h>
  71. #include<iostream.h>
  72. #include<conio.h>
  73.  
  74. main()
  75. {
  76. float mat1[10][10],mat2[10][10],mul[10][10];
  77. int i, j, k, L,M,N;
  78.  
  79. printf(“\t ESTE PROGRAMA MULTIPLICA DOS MATRICES”);
  80.  
  81. printf(“\n Introduzca el numero de filas de la matriz 1:”);
  82. scanf(“%d”,&N);
  83.  
  84. printf(“\n Introduzca el numero de columnas de la matriz 1 y filas de la matriz 2:”);
  85. scanf(“%d”,&M);
  86.  
  87. printf(“\n Introduzca el numero de columnas de la matriz 2:”);
  88. scanf(“%d”,&L);
  89.  
  90. // Solicitar y almacenar los valores de las matrices
  91.  
  92. printf(“\n\t Introduzca los valores de la MATRIZ 1 \n”);
  93.  
  94. for(i=0;i<N;i++)
  95. for(j=0;j<M;j++)
  96. {
  97. printf(“\n\t Mat1 [%d][%d]=”,i,j);
  98. scanf(“%f”,&mat1[i][j]);
  99. }
  100.  
  101. printf(“\n\t Introduzca los valores de la MATRIZ 2 \n”);
  102.  
  103. for(i=0;i<M;i++)
  104. for(j=0;j<L;j++)
  105. {
  106. printf(“\n\t Mat2 [%d][%d]=”,i,j);
  107. scanf(“%f”,&mat2[i][j]);
  108. }
  109.  
  110. //Imprimir los valores de las matrices en forma de filas y columas
  111.  
  112. printf(“\n\n\t Matriz 1\n”);
  113. for (i=0;i<N;i++)
  114. {
  115. printf(“\n\n\t”);
  116. for(j=0;j<M;j++)
  117. printf(“%12.2f”,mat1[i][j]);
  118. }
  119.  
  120. printf(“\n\n\t Matriz 2\n”);
  121. for (i=0;i<M;i++)
  122. {
  123. printf(“\n\n\t”);
  124. for(j=0;j<L;j++)
  125. printf(“%12.2f”,mat2[i][j]);
  126. }
  127.  
  128. //Realiza la multiplicación e imprime el resultado
  129.  
  130. for(i=0;i<N;i++)
  131. for(j=0;j<L;j++)
  132. {
  133. mul[i][j]=0;
  134. for(k=0;k<M;k++)
  135. {
  136.  
  137. mul[i][j]=(mul[i][j] +(mat1[i][k]*mat2[k][j]));
  138.  
  139. }
  140. }
  141. //Ahora solo tienes que mostrar el re
Advertisement
Add Comment
Please, Sign In to add comment