-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsparse.aditon.c
More file actions
87 lines (86 loc) · 2.06 KB
/
sparse.aditon.c
File metadata and controls
87 lines (86 loc) · 2.06 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
86
87
#include <stdio.h>
void add(int tup1[100][3],int tup2[100][3],int r,int c)
{
int i=0,j=0;
int tup3[100][3];
int k=0;
while(i<r&&j<c)
{
if(tup1[i][1]==tup2[j][1]&&tup1[i][0]==tup2[j][0])
{
tup3[k][2]=tup2[j][2]+tup1[i][2];
tup3[k][1]=tup2[j][1];
tup3[k][0]=tup2[j][0];
i++;
j++;
k++;
}
else if(tup1[i][0]<tup2[j][0]||(tup1[i][0]==tup2[j][0]&&tup1[i][1]<tup2[j][1]))
{
tup3[k][2]=tup1[i][2];
tup3[k][1]=tup1[i][1];
tup3[k][0]=tup1[i][0];
i++;
k++;
}
else
{
tup3[k][2]=tup2[j][2];
tup3[k][1]=tup2[j][1];
tup3[k][0]=tup2[j][0];
j++;
k++;
}
}
while(i<r)
{
tup3[k][2]=tup1[i][2];
tup3[k][1]=tup1[i][1];
tup3[k][0]=tup1[i][0];
i++;
k++;
}
while(j<c)
{
tup3[k][2]=tup2[j][2];
tup3[k][1]=tup2[j][1];
tup3[k][0]=tup2[j][0];
k++;
j++;
}
for(int i=0;i<k;i++)
{
for(int j=0;j<3;j++)
{
printf("%d ",tup3[i][j]);
}
printf("\n");
}
}
void main()
{
int n,n1;
printf("enter the no of elements of the 1st tuple");
scanf("%d",&n);
printf("enter the no of elements of the 2nd tuple");
scanf("%d",&n1);
int tup1[n][3],tup2[n1][3];
printf("enter the elements of 1st matrix");
for(int i=0;i<n;i++)
{
for(int j=0;j<3;j++)
{
scanf("%d",&tup1[i][j]);
}
}
printf("enter the elements of the second matrix");
for(int i=0;i<n1;i++)
{
for(int j=0;j<3;j++)
{
scanf("%d",&tup2[i][j]);
}
}
printf("final matrix\n");
add(tup1,tup2,n,n1);
}