-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathMatices.c
More file actions
85 lines (84 loc) · 1.51 KB
/
Matices.c
File metadata and controls
85 lines (84 loc) · 1.51 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
85
//C Program to add or subtract two matrices
#include<stdio.h>
#include<string.h>
void accept(int[10][10],int[10][10],int,int);
void display(int[10][10],int,int);
void add(int[10][10],int[10][10],int,int);
void subtract(int[10][10],int[10][10],int,int);
int main()
{
int a[10][10],b[10][10],r,c=0,ch=0;
printf("enter the no of rows\n");
scanf("%d",&r);
printf("enter the columns\n");
scanf("%d",&c);
accept(a,b,r,c);
printf("\n1.add\n2.subtract\n");
printf("enter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:add(a,b,r,c);
printf("\nsum of matrices is\n");
display(a,r,c);
break;
case 2: subtract(a,b,r,c);
printf("\ndifference of matrices is\n");
display(a,r,c);
break;
default:printf("invalid entry");
}
return 0;
}
void accept(int a[10][10],int b[10][10],int r,int c)
{ int j,i=0;
printf("enter the elements of array a\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("enter the elements of array b\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&b[i][j]);
}
printf("\n");
}
}
void add(int a[10][10],int b[10][10],int r,int c)
{ int j,i=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
a[i][j]+=b[i][j];
}
}
}
void subtract(int a[10][10],int b[10][10],int r,int c)
{ int j,i=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
a[i][j]-=b[i][j];
}
}
}
void display(int a[10][10],int r,int c)
{ int j,i=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
}