StudyLover
  • Home
  • Study Zone
  • Profiles
  • Contact us
  • Sign in
StudyLover 9. Program to implement matrix multiplication using arrays.
Download
  1. C++ Programs list
8. Program to find the factorial of a number using recursion. : 10. Program to calculate the average of all elements in an array.
C++ Programs list

1.      Program to implement matrix multiplication using arrays.

  1. #include <iostream.h>

  2. #include<conio.h>

  3. void multiplyMatrices(int A[][10], int B[][10], int C[][10], int m, int p, int n) {

  4.     for (int i = 0; i < m; i++) {

  5.                 for (int j = 0; j < n; j++) {

  6.                     C[i][j] = 0;

  7.                     for (int k = 0; k < p; k++) {

  8.                                 C[i][j] += A[i][k] * B[k][j];

  9.                     }

  10.                 }

  11.     }

  12. }

  13.  

  14. void printMatrix(int A[][10], int m, int n) {

  15.     for (int i = 0; i < m; i++) {

  16.                 for (int j = 0; j < n; j++) {

  17.                     cout << A[i][j] << " ";

  18.                 }

  19.                 cout << endl;

  20.     }

  21. }

  22.  

  23. int main() {

  24.     int A[10][10], B[10][10], C[10][10];

  25.     int m, n, p;

  26.  

  27.     cout << "Enter the dimensions of matrix A (m x p): ";

  28.     cin >> m >> p;

  29.  

  30.     cout << "Enter the elements of matrix A:\n";

  31.     for (int i = 0; i < m; i++) {

  32.                 for (int j = 0; j < p; j++) {

  33.                     cin >> A[i][j];

  34.                 }

  35.     }

  36.  

  37.     cout << "Enter the dimensions of matrix B (p x n): ";

  38.     cin >> p >> n;

  39.  

  40.     cout << "Enter the elements of matrix B:\n";

  41.     for ( i = 0; i < p; i++) {

  42.         for (int j = 0; j < n; j++) {

  43.             cin >> B[i][j];

  44.         }

  45.     }

  46.  

  47.     multiplyMatrices(A, B, C, m, p, n);

  48.  

  49.     cout << "Product of A and B:\n";

  50.     printMatrix(C, m, n);

  51.     getch();

  52.     return 0;

  53. }

  54.  

8. Program to find the factorial of a number using recursion. 10. Program to calculate the average of all elements in an array.
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website