Want more features on Pastebin? Sign Up, it's FREE!
Guest

Suma y resta de matrices

By: eztlicoatl on Apr 11th, 2011  |  syntax: C++  |  size: 1.43 KB  |  views: 229  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <dos.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <iostream.h>
  5.  
  6. int A[3][3],B[3][3],C[3][3],D[3][4],E[4][3],i,j,opcion;
  7. void resta(int A[3][3],int B[3][3]);
  8. void mult(int D[3][4],int E[4][3]);
  9.  
  10. void main(){
  11. clrscr();
  12. cout<<"Elige una de las siguientes opciones:\n1.-Resta de matrices\n2.-Multiplicacion de matrices\n\n";
  13. cin>>opcion;
  14.  
  15. switch (opcion){
  16. case 1:
  17. cout<<"Introduce los valores de la matriz A: \n\n";
  18. for(i=0;i<=2;i++){
  19. for(j=0;j<=2;j++){
  20. cout<<"A["<<i+1<<"]["<<j+1<<"]= ";
  21. cin>>A[i][j];
  22. }
  23. }
  24.  
  25. cout<<"\nA=\n";
  26. for(i=0;i<=2;i++){
  27. for(j=0;j<=2;j++){
  28. cout<<A[i][j]<<"\t";
  29. }
  30. cout<<"\n";
  31. }
  32.  
  33. cout<<"\nIntroduce los valores de la matriz B: \n\n";
  34. for(i=0;i<=2;i++){
  35. for(j=0;j<=2;j++){
  36. cout<<"B["<<i+1<<"]["<<j+1<<"]= ";
  37. cin>>B[i][j];
  38. }
  39. }
  40.  
  41. cout<<"\nB=\n";
  42. for(i=0;i<=2;i++){
  43. for(j=0;j<=2;j++){
  44. cout<<B[i][j]<<"\t";
  45. }
  46. cout<<"\n";
  47. }
  48.  
  49. resta(A,B);
  50. break;
  51.  
  52. case 2:
  53. cout<<"Introduce los valores de la matriz A: \n\n";
  54. for(i=0;i<=2;i++){
  55. for(j=0;j<=2;j++){
  56. cout<<"A["<<i+1<<"]["<<j+1<<"]= ";
  57. cin>>A[i][j];
  58. }
  59. }
  60.  
  61. cout<<"\nA=\n";
  62. for(i=0;i<=2;i++){
  63. for(j=0;j<=2;j++){
  64. cout<<A[i][j]<<"\t";
  65. }
  66. cout<<"\n";
  67. }
  68. break;
  69. }
  70. getch();
  71. }
  72.  
  73. void resta(int A[3][3], int B[3][3]){
  74.  
  75. cout<<"\nRestando A y B...\n\n";
  76. for(i=0;i<=2;i++){
  77. for(j=0;j<=2;j++){
  78. C[i][j]=A[i][j]-B[i][j];
  79. }
  80. }
  81.  
  82. cout<<"\nC=\n";
  83. for(i=0;i<=2;i++){
  84. for(j=0;j<=2;j++){
  85. cout<<C[i][j]<<"\t";
  86. }
  87. cout<<"\n";
  88. }
  89. }
clone this paste RAW Paste Data