Search
 
SCRIPT & CODE EXAMPLE
 

C

matrix multiplication in c

#include<stdio.h>
void main(){
    int row1,column1,row2,column2,i,j,k,a[100][100],b[100][100],mul[100][100];
    //a[][] for first matrix and b for second matrix b[][]

    printf("Enter number of rows of first matrix : ");
    scanf("%d",&row1);
    printf("Enter number of columns of first matrix : ");
    scanf("%d",&column1);
    
    printf("#### Frist Matrix ####
");
    for(i=0;i<row1;i++){
        for(j=0;j<column1;j++){
            printf("Enter element a %d%d : ",i+1,j+1);
            scanf("%d",&a[i][j]);
        }
    }

    printf("Enter number of rows of second matrix : ");
    scanf("%d",&row2);
    printf("Enter number of columns of second matrix : ");
    scanf("%d",&column2);
    
    printf("#### Second Matrix ####
");
    for(i=0;i<row2;i++){
        for(j=0;j<column2;j++){
            printf("Enter element a %d%d : ",i+1,j+1);
            scanf("%d",&b[i][j]);
        }
    }
    if(column1 == row2){
        for(i=0;i<row1;i++){
            for(j=0;j<column2;j++){
                mul[i][j] = 0;
            }
        }
        
        for(i=0;i<row1;i++){
            for(j=0;j<column2;j++){
                for(k=0;k<row2;k++){  //as row2 = column1
                    mul[i][j] = mul[i][j] + a[i][k] * b[k][j];
                }
            }
        }
        
        for(i=0;i<row1;i++){
            for(j=0;j<column2;j++){
                printf("%d ",mul[i][j]);
            }
            printf("
");
        }
        
    }
}
Comment

how to do matrix multiplication in c

double[][] c = new double[N][N];
for (int i = 0; i < N; i++)
{
 for (int j = 0; j < N; j++)
 	{
 for (int k = 0; k < N; k++)
 		{
		 c[i][j] += a[i][k] * b[k][j];
 		}
 	}
}
Comment

matrix multiplication in c

#include <stdio.h>

int main()
{   int a_rows,a_cols,b_rows,b_cols,i,j,k,sum=0;

    printf("Enter the rows and columns for first matrix (row)(col)  :
");
    scanf("%d %d",&a_rows,&a_cols);

    printf("Enter the rows and columns for second matrix (row)(col) :
");
    scanf("%d %d",&b_rows,&b_cols);
    int a[a_rows][a_cols], b[b_rows][b_cols],matrix[10][10];

    if(a_cols != b_rows){
        printf("Sorry! We can't multiply the matrix because the column number of matrix 1 and the row number of matrix 2 aren't same !!
");
        
    }else{
        printf("Enter elements for first matrix  :
");
       for(i = 0; i < a_rows; i++){
           for(j = 0; j< a_cols; j++){
               scanf("%d",&a[i][j]);
           }
       }

    printf("Enter elements for second matrix  :
");

       for(i = 0; i < b_rows; i++){
           for(j = 0; j < b_cols; j++){
               scanf("%d",&b[i][j]);
           }
       }

       printf("multiplying matrix....
");
       //multiplying matrix
       for(i=0; i < a_rows; i++){
           for(j = 0; j < b_cols; j++){
               for(k = 0; k < a_cols; k++){
                   sum+=a[i][k] * b[k][j];
               }
               matrix[i][j] = sum;
               sum=0;
               
           }
           printf("
");
       }

       printf("first matrix  :
");
       for(i = 0; i < a_rows; i++){
           for(j = 0; j< a_cols; j++){
               printf("%d ",a[i][j]);
           }
           printf("
");
       }


        printf("

");

       printf("second matrix  :
");
       for(i = 0; i < b_rows; i++){
           for(j = 0; j< b_cols; j++){
               printf("%d ",b[i][j]);
           }
           printf("
");
       }


       printf("Multiplied matrix  :
");
       for(i = 0; i < a_rows; i++){
           for(j = 0; j< b_cols; j++){
               printf("%d ",matrix[i][j]);
           }
           printf("
");
       }
    }

     

    return 0;
}
Comment

multiplication table in c using array

#include <stdio.h>

int main()
{
    int namta[11][10]; //programme will run upto 11 multiplication tables, each table has 10 columns
    int i,j;
    for(i = 1; i <= 11; i++)
    {
        for(j = 1; j <= 10; j++)
        {
            namta[i][j] = i * j;  //getting the multiplating value into the array
        }
    }

    for(i = 1; i <= 10; i++){
        for(j = 1; j <= 10; j++){
            printf("%d x %d = %d
",i,j,namta[i][j]);  //printing the array of results calculated in the previous loops
        }
        printf("
");
    }


    return 0;
}
Comment

multiplication of matrix in c

enter the number of row=3
enter the number of column=3
enter the first matrix element=
1 1 1
8 8 8
3 3 3
enter the second matrix element=
1 1 1
2 2 2
3 3 3
multiply of the matrix=
6 6 6
12 12 12
18 18 18
Comment

matrix multiplication in c

Matrix Multification
Comment

PREVIOUS NEXT
Code Example
C :: c concatenate and allocate string 
C :: int data types in c 
C :: mongodb read 
C :: C program for float division of numbers 
C :: malloc c 
C :: stdio.h 
C :: KneesDev 
C :: eliminare file in c 
C :: pasar a binario recursivo 
C :: declaration in c 
C :: c str add int 
C :: getline() in c 
C :: how to use pointer in c to print char 
C :: define constant c 
C :: armstrong in c 
C :: functions in c programming 
C :: Install valet-linux 
C :: what does packing mean in c 
C :: allintext:christie kiser filetype:log 
C :: metw.cc 
C :: print in c 11111 00000 11111 00000 11111 
C :: c %d 
C :: tytykjtuky 
C :: set all pins as input for loop 
C :: condition ternaire in c 
C :: pre-commit configuration 
C :: timespec c 
C :: Print the number 0 using write() 
C :: buildCheckFunction(locations) 
C :: C (Windows) 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =