Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C Compiler.
  4. Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10.  
  11. int main()
  12. {
  13. int N, M, N1, M1, i, j, k, n;
  14. int A[n][n];
  15. int B[n][n];
  16. int C[n][n];
  17. printf("Введите количество строк первой матрицы: ");
  18. scanf("%d", &N);
  19. printf("Введите количество столбцов первой матрицы: ");
  20. scanf("%d", &M);
  21. printf("Заполните матрицу A:\n");
  22. for (i = 0; i < N; i++)
  23. for (j = 0; j < M; j++)
  24. {
  25. scanf("%d", &A[i][j]);
  26. }
  27. printf("Введите количество строк второй матрицы: ");
  28. scanf("%d", &N1);
  29. printf("Введите количество столбцов второй матрицы: ");
  30. scanf("%d", &M1);
  31. if (M != N1)
  32. printf("Эти матрицы невозможно перемножить");
  33. else
  34. {
  35. printf("Заполните матрицу B:\n");
  36. for (i = 0; i < N1; i++)
  37. for (j = 0; j < M1; j++)
  38. {
  39. scanf("%d", &B[i][j]);
  40. }
  41. for (i = 0; i < N; i++)
  42. for (j = 0; j < M; j++)
  43. {
  44. C[i][j] = 0;
  45. for (k = 0; k < M1; k++)
  46. C[i][j] += A[i][k] * B[k][j];
  47. }
  48. }
  49. printf("\nПри умножении получаем матрицу порядка %dx%d\n", N, M1);
  50. for (i = 0; i < N; i++)
  51. {
  52. for (j = 0; j < M1; j++)
  53. printf("%d ", C[i][j]);
  54. printf("\n");
  55. }
  56.  
  57.  
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement