#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;