multiply matrix in c

Solutions on MaxInterview for multiply matrix in c by the best coders in the world

showing results for - "multiply matrix in c"
Antonio
23 Jul 2016
1double[][] c = new double[N][N];
2for (int i = 0; i < N; i++)
3{
4 for (int j = 0; j < N; j++)
5 	{
6 for (int k = 0; k < N; k++)
7 		{
8		 c[i][j] += a[i][k] * b[k][j];
9 		}
10 	}
11}
12
Samantha
29 Mar 2017
1#include <stdio.h>
2
3void main ()
4{
5    int i, j, k, m1, n1, m2, n2;
6    int matrix1[10][10],matrix2[10][10],mult[10][10];
7
8    printf("Enter number of rows of matrix 1 : ");
9    scanf("%d", &m1);
10    printf("Enter number of columns of matrix 1 : ");
11    scanf("%d", &n1);
12
13    printf("\n");
14
15    for (i = 0; i < m1; i++)
16    {
17        for (j = 0; j < n1; j++)
18        {
19            printf("Enter element of matrix 1[%d][%d]: ", i, j);
20            scanf("%d", &matrix1[i][j]);
21        }
22    }
23
24    printf("\n");
25
26    printf("Enter number of rows of matrix 2 : ");
27    scanf("%d", &m2);
28    printf("Enter number of columns of matrix 2 : ");
29    scanf("%d", &n2);
30
31    printf("\n");
32
33    if(m1==n2)
34    {
35        for (i = 0; i < m2; i++)
36        {
37            for (j = 0; j < n2; j++)
38            {
39                printf("Enter elements of matrix 2[%d][%d]: ", i, j);
40                scanf("%d", &matrix2[i][j]);
41            }
42        }
43
44        printf("\n");
45
46        printf("\n....Your resultant matrix is....\n\n");
47
48       for(i=0;i<m1;i++)
49        {
50            for(j=0;j<n2;j++)
51            {
52                mult[i][j]=0;
53                for(k=0;k<m2;k++)
54                {
55                    mult[i][j]+=matrix1[i][k]*matrix2[k][j];
56                }
57            }
58        }
59
60        for (i = 0; i < m1; i++)
61        {
62            for (j = 0; j < n2; j++)
63            {
64                printf("%d\t", mult[i][j]);
65            }
66            printf("\n");
67        }
68
69    }
70
71    else
72        printf("Matrix multiplication not possible");
73}
74
75
76
Alessio
09 Oct 2017
1#include <stdio.h>
2
3// function to get matrix elements entered by the user
4void getMatrixElements(int matrix[][10], int row, int column) {
5
6   printf("\nEnter elements: \n");
7
8   for (int i = 0; i < row; ++i) {
9      for (int j = 0; j < column; ++j) {
10         printf("Enter a%d%d: ", i + 1, j + 1);
11         scanf("%d", &matrix[i][j]);
12      }
13   }
14}
15
16// function to multiply two matrices
17void multiplyMatrices(int first[][10],
18                      int second[][10],
19                      int result[][10],
20                      int r1, int c1, int r2, int c2) {
21
22   // Initializing elements of matrix mult to 0.
23   for (int i = 0; i < r1; ++i) {
24      for (int j = 0; j < c2; ++j) {
25         result[i][j] = 0;
26      }
27   }
28
29   // Multiplying first and second matrices and storing it in result
30   for (int i = 0; i < r1; ++i) {
31      for (int j = 0; j < c2; ++j) {
32         for (int k = 0; k < c1; ++k) {
33            result[i][j] += first[i][k] * second[k][j];
34         }
35      }
36   }
37}
38
39// function to display the matrix
40void display(int result[][10], int row, int column) {
41
42   printf("\nOutput Matrix:\n");
43   for (int i = 0; i < row; ++i) {
44      for (int j = 0; j < column; ++j) {
45         printf("%d  ", result[i][j]);
46         if (j == column - 1)
47            printf("\n");
48      }
49   }
50}
51
52int main() {
53   int first[10][10], second[10][10], result[10][10], r1, c1, r2, c2;
54   printf("Enter rows and column for the first matrix: ");
55   scanf("%d %d", &r1, &c1);
56   printf("Enter rows and column for the second matrix: ");
57   scanf("%d %d", &r2, &c2);
58
59   // Taking input until
60   // 1st matrix columns is not equal to 2nd matrix row
61   while (c1 != r2) {
62      printf("Error! Enter rows and columns again.\n");
63      printf("Enter rows and columns for the first matrix: ");
64      scanf("%d%d", &r1, &c1);
65      printf("Enter rows and columns for the second matrix: ");
66      scanf("%d%d", &r2, &c2);
67   }
68
69   // get elements of the first matrix
70   getMatrixElements(first, r1, c1);
71
72   // get elements of the second matrix
73   getMatrixElements(second, r2, c2);
74
75   // multiply two matrices.
76   multiplyMatrices(first, second, result, r1, c1, r2, c2);
77
78   // display the result
79   display(result, r1, c2);
80
81   return 0;
82}
Dion
11 May 2020
1#include <stdio.h>
2void enterData(int first[][10], int second[][10], int r1, int c1, int r2, int c2);
3void multiplyMatrices(int first[][10], int second[][10], int multResult[][10], int r1, int c1, int r2, int c2);
4void display(int mult[][10], int r1, int c2);
5
6int main() {
7    int first[10][10], second[10][10], mult[10][10], r1, c1, r2, c2;
8    printf("Enter rows and column for the first matrix: ");
9    scanf("%d %d", &r1, &c1);
10    printf("Enter rows and column for the second matrix: ");
11    scanf("%d %d", &r2, &c2);
12
13    // Taking input until columns of the first matrix is equal to the rows of the second matrix
14    while (c1 != r2) {
15        printf("Error! Enter rows and columns again.\n");
16        printf("Enter rows and columns for the first matrix: ");
17        scanf("%d%d", &r1, &c1);
18        printf("Enter rows and columns for the second matrix: ");
19        scanf("%d%d", &r2, &c2);
20    }
21
22    // Function to take matrices data
23    enterData(first, second, r1, c1, r2, c2);
24
25    // Function to multiply two matrices.
26    multiplyMatrices(first, second, mult, r1, c1, r2, c2);
27
28    // Function to display resultant matrix after multiplication.
29    display(mult, r1, c2);
30
31    return 0;
32}
33
34void enterData(int first[][10], int second[][10], int r1, int c1, int r2, int c2) {
35    printf("\nEnter elements of matrix 1:\n");
36
37    for (int i = 0; i < r1; ++i) {
38        for (int j = 0; j < c1; ++j) {
39            printf("Enter a%d%d: ", i + 1, j + 1);
40            scanf("%d", &first[i][j]);
41        }
42    }
43    printf("\nEnter elements of matrix 2:\n");
44
45    for (int i = 0; i < r2; ++i) {
46        for (int j = 0; j < c2; ++j) {
47            printf("Enter b%d%d: ", i + 1, j + 1);
48            scanf("%d", &second[i][j]);
49        }
50    }
51}
52
53void multiplyMatrices(int first[][10], int second[][10], int mult[][10], int r1, int c1, int r2, int c2) {
54
55    // Initializing elements of matrix mult to 0.
56    for (int i = 0; i < r1; ++i) {
57        for (int j = 0; j < c2; ++j) {
58            mult[i][j] = 0;
59        }
60    }
61
62    // Multiplying first and second matrices and storing in mult.
63    for (int i = 0; i < r1; ++i) {
64        for (int j = 0; j < c2; ++j) {
65            for (int k = 0; k < c1; ++k) {
66                mult[i][j] += first[i][k] * second[k][j];
67            }
68        }
69    }
70}
71
72void display(int mult[][10], int r1, int c2) {
73
74    printf("\nOutput Matrix:\n");
75    for (int i = 0; i < r1; ++i) {
76        for (int j = 0; j < c2; ++j) {
77            printf("%d  ", mult[i][j]);
78            if (j == c2 - 1)
79                printf("\n");
80        }
81    }
82}
83
queries leading to this page
matrix multiplication in c 2d arraymultiply 2 matrices in cwrite a c program for multiplication of two matrices matrix multiplication using function in cmultiplying matrix in cmatrix multiplication in c 2b 2bmultiplication function in cmatrix multiplication i n cc program to find multipilication of 2 matricesmatrix multiplication in c using functionmultiply two matrix c2d array multiplication in cmatrix multiplication codingmatrix multplication of 2 matrix in cc program for the matrix multiplication2 2a2 and 2 2a3 matrix multiplication in cproduct of 2 marix in cmatrix multiplication using c programmultiplication of 2 matrices in cc matrix multiplicationmultiplication of matrix in c using 2d arrayarray multiply programc code for multiplication of matrix in placearray of integers multiplication in cmatrix multiplication function c languagec code for multiplication of two matriceswrite a program to implement multiplication of matrices in cmatrix operations in c programmatrix multiplication program in chow to multiply two arrays in cmultiplying any 2 matrices in cmatrix multiplicaytion cwrite a c program to find the matrix multiplication of two matrices matrix multiplication using cproduct of matrix in c programmatrix multiplication in array cmultiplication of arrays in cmultiplication of square matrix in carrys in multiplication two matrices in c programarray multiplication in cprogram to print out multiplcation array in cprogram to find multiplication of two matricesc metric multiplacationwrite a program to print the multiplication of two n 2an 28square 29 matrix how to code matrix multiplication in c2d array multiplication cc program for matrix multiplication using functionssproduct of matrix in cc program to multiply two matriceswrite a program to calculate matrix multiplicationcode for matrix multiplicationmultiply two rectangular matrixes using ctwo dimensional array in c multiplicationc matrix multiplication functionaddition of two matrix in c programproduct c of matricematrix multiplication programmatrix multiplication in c programwrite a program for matrix multiplication in cmatrix multiplication data structurec code of matrix multiplymultiplication of matrix program in chow to multiply 2 matrices in chow to do matrix multiplication in cwrite a program to print multiplication of two matricesc matrix multiplication for loopmatrix multiplication c programwap to multiply 2 matrix2x2 matrix multiplication in cc program to multiply two matrix using multi dimensional arrayswrite a program to perform matrix multiplication multiplication of two matrices codehow to multiply matrix in cmultiplication of 2d array in cmatrix multiplication cmatrices in cmatrix operations in ccode for matrix multiplicationc program multiply matrixmatrix program in cgiven two matrices multiply them and output the matrixsimple matrix programs in cmultiply matrices in c multiplying matrices in cmatrix multiplication in c with different dimensionsmultiplication of two matrices in cmultiplication of three matrices in cuse in matrix computations in c programminghow to program matrix multiplicationright multiply matrix cmatrix addition in cmultiply array in calgorithm to multiply two matrices in cprogram for matrix multiplication in cc multiply matricesc program for matrix multiplicationhow to code matrix multiplication in c with a matrixmatrix multiplication in cmultiplying two atrix programc program to multiply 5 matricesmultiplication of 2 matrices codematrix transpore in cmultiply arrays in cwrite a programme to multiply two matrices in cc program for multiplication of two 3x3 matricesmatrix multiplication code in c gfg2d array matrix multiplication in c language program multiplying two matrices in cmatrix multiplication with different dimensions in cwap to 3a a multiply two matrixes b find the transpose of a given matrix in cmultiplication arrays codewrite a c program for matrix multiplicationcode in c for matrix multiplicationblock multiplication of matrices program in cmultiplication of matrices in cc matrix multiplymatrix multiplication in c logicc matrix multiplication o 28n 29multiplication of matrix 2 2a2 codewap to multiply two matrices in cwrite a c program to multiply two matrices multiply matrix function cmatrix multiplication code in cmultiply matrix in cc programming multiplying matricesc program to implement matrix multiplicationsquare matrix multiplication in cmatrix multiplication algorithm in cc program multiplication of two matrixwrite c programs to read two matrices and find the addition and multiplication of two matriceshow to take multiple matrix based on user in cmatri multiplicarion c explainhow to do matrix multiplication in 2d array 27matrix in c program matrix multiplication logicc program of matrix multiplicationmatrix multiplication code in c2d matrix multiplicationmultiply two matrix in calgorithm for matrix multiplication in cmultiplication of two matrix in cc multiply matrixc matrix multiplication librarymatrix multiplication c codematrix multiplication cmultiplication of any two matrix in chow to multiply matrices in cmultiplication of 22three 22 matrices in ccode for matrx multiplication 2dwrite a c program to perform matrix multiplicationcode of matrix multiplication in cmatrix code in c 2 2a 40matricx multiplication in c matrix multiplication in cmultiply two matrices in cwrite a c program for matrix multiplication using operator overloadingmatrix multiplication codemultiplication matrix in cc program for multiplying two matriceswrite a shell script for multiplying 2 matrices and printing the resultantmatrix here youneed to represent a 2 dimensional matrix using a 1 dimensional arraymatriz multiplication clogic of matrix multiplication in c 3a write a c program for multiplication of the two matrixmultiplying two matrices c programc program to find matrix multiplication using arrays2 2a2 and 2 2a1 matrix multiplication in cmatrix multiplication programmingperform matrix multiplication using cmatrix multiplication prgramhow to have product of two matix in cmultiplication array in cmatrix matrix multiplication carray multiplication cprogram to multiply two matrix in cmultiplication of 2d arraymatrix multiplicationin cmatrix multiplication i c programizprogram of multiply two matrices in cmulti matrix cmatrices multiplication in cmatrix multiplication in c using arrayprogram for product of two matriceswrite a c program to implement matrix multiplication of three matriksmultiply matrix cc code for matrix multiplicationsimple matrix program in cmultiplication matrix table c if statementmatrix multiplciation in cmultiply matric in cc program to find matrix multiplicationmath h array multiplicationmultiply array elements in ccalculate product of 2 matrix in cproduct of 2 matrices in cc program for matrix multiplicationprogram for matrix multiplicationmultiply the two matrices cprogram for matrix multiplication using array in cproduct of 2d array in carray of multiplication cmultiplication of 2 2 matrix c programmatrix multiplication cc add two matrixwrite a program to multiply two matrices in cmatrix multiplication write a program to perform matrix multiplication assume only square matrices of the same dimension multiple matrix array3 3 matrix multiplication in cwrite a c program to implement three matrices multiplicationresults for matrix multiplication in cmultiplication of a matrix in c write a program to implement matrix multiplication write a c program multiplication of two matrixmultiply of matrix in cmultiply matrices c programmatrix in c programmingalgorithm to multiply matrices in cmultiplying any 2 matrices in c codemultiplication of matrix 2 2a2 code in cprogram to multiply two matrices in cwrite a program to multiply 2 matrices in crule for matrix multiplication in cc matrix mathmatrix multiplication from file in cmatrices multiplication program in cc program to multiply n xn matrixmultipication matrices cimplement matrix multiplication in cmultiplication of 2d matrix in cmatrix right multiplication in cmatrix multiply in cm 2an matrix multiplication in cresult for matrix multiplication in c3 2a3 matrix multiplication in cmatrix programming in cmultiplication of m 2an matrices in cc multiply two matricesmultiplication two matrices by using 2 dimensional array in cprogram to multiply 2 matrices in cmultiply 2 matrice codemultiplication of matrix cmultiplication of matrix in cmultiply matrix in c