fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define ZEILENZAHL1 4
  6. #define SPALTENZAHL1 3
  7. #define ZEILENZAHL2 3
  8. #define SPALTENZAHL2 4
  9. #define ZEILENZAHL3 4
  10. #define SPALTENZAHL3 4
  11.  
  12. void funktioneingabematrix1(int[][SPALTENZAHL1],int);
  13. void funktioneingabematrix2(int[][SPALTENZAHL2],int);
  14. void funktionberechnungergebnismatrix(int[][SPALTENZAHL3],int[][SPALTENZAHL1],int[][SPALTENZAHL2]);
  15. void funktionausgabeergebnismatrix(int[][SPALTENZAHL3]);
  16.  
  17. int main()
  18. {
  19. int matrix1[ZEILENZAHL1][SPALTENZAHL1],
  20. matrix2 [ZEILENZAHL2][SPALTENZAHL2],
  21. ergebnismatrix[ZEILENZAHL3][SPALTENZAHL3];
  22.  
  23. funktioneingabematrix1(matrix1,ZEILENZAHL1);
  24.  
  25. funktioneingabematrix2(matrix2,ZEILENZAHL2);
  26.  
  27. funktionberechnungergebnismatrix(ergebnismatrix, matrix1, matrix2);
  28.  
  29. funktionausgabeergebnismatrix(ergebnismatrix);
  30.  
  31. return 0;
  32. }
  33.  
  34.  
  35. void funktioneingabematrix1(int matrix1[][SPALTENZAHL1],int z1)
  36. {
  37. int zaehl1,zaehl2, counter=0;
  38. printf("Bitte geben Sie die erste Matrix ein\n");
  39. for(zaehl1=0;zaehl1<z1;zaehl1++)
  40. for(zaehl2=0;zaehl2<SPALTENZAHL1;zaehl2++)
  41. {
  42. scanf("%i",&matrix1[zaehl1][zaehl2]);
  43. counter++;
  44. if(counter==SPALTENZAHL1)
  45. {
  46. printf("\n");
  47. counter=0;
  48. }
  49. }
  50.  
  51. }
  52.  
  53. void funktioneingabematrix2(int matrix2[][SPALTENZAHL2],int z2)
  54. {
  55. int zaehl1,zaehl2, counter=0;
  56. printf("Bitte geben Sie die zweite Matrix ein\n");
  57. for(zaehl1=0;zaehl1<z2;zaehl1++)
  58. for(zaehl2=0;zaehl2<SPALTENZAHL2;zaehl2++)
  59. {
  60. scanf("%i",&matrix2[zaehl1][zaehl2]);
  61. counter++;
  62. if(counter==SPALTENZAHL2)
  63. {
  64. printf("\n");
  65. counter=0;
  66. }
  67. }
  68. counter=0;
  69. }
  70.  
  71. void funktionberechnungergebnismatrix(int e[][SPALTENZAHL3],int m1[][SPALTENZAHL1],int m2[][SPALTENZAHL2])
  72. {
  73. int zaehl1,zaehl2,x=0;
  74. for(zaehl1=0;zaehl1<ZEILENZAHL3;zaehl1++)
  75. for(zaehl2=0;zaehl2<SPALTENZAHL3;zaehl2++)
  76. for(e[zaehl1][zaehl2]=x=0;x<SPALTENZAHL1;++x)
  77. e[zaehl1][zaehl2]+=m1[zaehl1][x]*m2[x][zaehl2];
  78. }
  79.  
  80. void funktionausgabeergebnismatrix(int ergebnismatrix[][SPALTENZAHL3])
  81. {
  82. int zaehl1,zaehl2, counter=0;
  83. printf("Die resultierende Matrix aus Matrix1 * Matrix 2 lautet: \n");
  84. for(zaehl1=0;zaehl1<ZEILENZAHL3;zaehl1++)
  85. for(zaehl2=0;zaehl2<SPALTENZAHL3;zaehl2++)
  86. {
  87. printf("%i ", ergebnismatrix[zaehl1][zaehl2]);
  88. counter++;
  89. if(counter==SPALTENZAHL3)
  90. {
  91. printf("\n");
  92. counter=0;}
  93. }
  94.  
  95. }
  96.  
Success #stdin #stdout 0s 2056KB
stdin
2
2
2
2
2
2
2
2
2
2
2
2
4
4
4
4
4
4
4
4
4
4
4
4
stdout
Bitte geben Sie die erste Matrix ein




Bitte geben Sie die zweite Matrix ein



Die resultierende Matrix aus Matrix1 * Matrix 2 lautet: 
24 24 24 24 
24 24 24 24 
24 24 24 24 
24 24 24 24