Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views3 pages

Include

The document contains a C program that multiplies two matrices. It defines functions for matrix multiplication and printing the result, while also handling user input for matrix dimensions and elements. The program checks for compatibility in matrix dimensions before performing the multiplication.

Uploaded by

rutger.jossiah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Include

The document contains a C program that multiplies two matrices. It defines functions for matrix multiplication and printing the result, while also handling user input for matrix dimensions and elements. The program checks for compatibility in matrix dimensions before performing the multiplication.

Uploaded by

rutger.jossiah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<stdio.

h>

#define max 10//define a maxinum size for the matrices

void multiplymatrices(int first[max][max], int second[max][max], int result[max][max], int r1, int c1, int
r2, int c2)

for(int i=0;i<r1;i++){

for(int j=0;j<c2;j++){

result[i][j]=0;//initialize the result element

for(int k=0;k<c1;k++){

result [i][j]+=first[i][k]

*second[k][j];//perform multiplication and accumulation

void printmatrix(int matrix[max][max],int rows,int cols){

for(int i=0;i<rows;i++){

for(int j=0;j<cols;j++){

printf("%d",matrix[i][j]);

printf("\n");

int main(){

int first[max][max], second[max][max], result[max][max];

int r1,c1,r2,c2;

//in put first matrix dimensions

printf("enter rows and colums for frist matrix:");


scanf("%d",&c1);

//input first matrix

printf("enter elements of first matrix:\n");

for(int i=0;i<r1;i++) {

for(int j=0;j<c1;j++){

scanf("%d",&first[i][j]);

//input second matrix

printf("enter rows and columns for second matrix;");

scanf("%d%d",&r2,c2);

//check if multiplication is posible

if(c1!=r2){

printf("error:number of colums in the frist matrix must eqal the number of rows in the second matrix.\
n");

return 1;

//input second matrix

printf("enter elements of second matrix:\n");

for(int i=0;i<r2;i++){

for(int j=0;j<c2;j++){

scanf("%d",&second[i][j]);

//perform multiplication

multiplymatrices(first,second,result,r1,c1,r2,c2);

//print the result

printf("result matrix after multiplication:\n");

printmatrix(result,r1,c2);
return 0;

You might also like