-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriplet.c
78 lines (77 loc) · 1.23 KB
/
triplet.c
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
#include<stdio.h>
void main()
{
int a[50][50],r,c,i,j;
printf("Enter the no of rows and columns : \n");
scanf("%d%d",&r,&c);
printf("Enter the elements : \n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("The entered matrix is :\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
int triplet[50][50],k=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(a[i][j]!=0)
{
k++;
triplet[k][0]=i;
triplet[k][1]=j;
triplet[k][2]=a[i][j];
}
}
}
triplet[0][0]=r;
triplet[0][1]=c;
triplet[0][2]=k;
printf("The triplet is : \n");
for(i=0;i<triplet[0][2]+1;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",triplet[i][j]);
}
printf("\n");
}
int transpose[50][50];
k=0;
for(i=0;i<triplet[0][1];i++)
{
for(j=1;j<=triplet[0][2];j++)
{
if(triplet[j][1]==i)
{
k++;
transpose[k][0]=triplet[j][1];
transpose[k][1]=triplet[j][0];
transpose[k][2]=triplet[j][2];
}
}
}
transpose[0][0]=triplet[0][1];
transpose[0][1]=triplet[0][0];
transpose[0][2]=triplet[0][2];
printf("The transpose is :\n");
for(i=0;i<transpose[0][2]+1;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",transpose[i][j]);
}
printf("\n");
}
}