forked from PrabhudeepSingh/C-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiplyMatrices.c
More file actions
84 lines (75 loc) · 1.65 KB
/
MultiplyMatrices.c
File metadata and controls
84 lines (75 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//Program to multiply two matrix
#include<stdio.h>
#include<process.h>
#include<unistd.h>
int main()
{
int r1,c1,r2,c2,i,j,k;
float a[10][10],b[10][10],d[10][10];
printf("Enter the number of rows of first matrix : ");
scanf("%d",&r1);
while(r1<=0||r1>10)
{
printf("Error... Range of Rows is 0 - 10 ");
printf("\nEnter the number of Rows again for first matrix : ");
scanf("%d",&r1);
}
printf("\nEnter the number of columns of first matrix : ");
scanf("%d",&c1);
while(c1<=0||c1>10)
{
printf("Error... Range of Columns is 0 - 10 ");
printf("\nEnter the number of Columns again for first matrix : ");
scanf("%d",&c1);
}
r2=c1;
printf("\nNumber of rows in second matrix is taken as : %d\n",r2);
printf("\nEnter the number of columns of second matrix : ");
scanf("%d",&c2);
while(c2<=0||c2>10)
{
printf("Error... Range of Columns is 0 - 10 ");
printf("\nEnter the number of Columns again for Second matrix : ");
scanf("%d",&c2);
}
printf("\nEnter the first matrix :\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("Enter the element at location a[%d][%d] : ",i+1,j+1);
scanf("%f",&a[i][j]);
}
}
printf("\nEnter the Second matrix :\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("Enter the element at location a[%d][%d] : ",i+1,j+1);
scanf("%f",&b[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
d[i][j]=0.0;
for(k=0;k<r2;k++)
{
d[i][j]=d[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\nThe multiplication of matrices results into : \n\n");
sleep(1);
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf("%.2f\t",d[i][j]);
}
printf("\n");
}
return 0;
}