-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfast_transpose_2.c
56 lines (52 loc) · 1.09 KB
/
fast_transpose_2.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
#include<stdio.h>
typedef struct
{
int r,c,v;
} term;
void transpose(term a[],term t[])
{
int rt[10],sp[10];
int i,j,numcols=a[0].c,numterms=a[0].v;
t[0].r=numcols;
t[0].v=numterms;
t[0].c=a[0].r;
if(numterms>0)
{
for(i=0;i<numcols;i++)
rt[i]=0;
for(i=1;i<=numterms;i++)
rt[a[i].c]++;
sp[0]=1;
for(i=1;i<numcols;i++)
sp[i]=sp[i-1]+rt[i-1];
for(i=1;i<=numterms;i++)
{
j=sp[a[i].c]++;
t[j].r=a[i].c;
t[j].c=a[i].r;
t[j].v=a[i].v;
}
}
}
int main()
{
term a[10],t[10];
int i;
printf("\nEnter the number of rows and columns\n");
scanf("%d%d",&a[0].r,&a[0].c);
printf("\nEnter the number of values\n");
scanf("%d",&a[0].v);
for(i=1;i<=a[0].v;i++)
{
printf("\nEnter row, column and element value and press enter key\n");
scanf("%d%d%d",&a[i].r,&a[i].c,&a[i].v);
}
printf("\nOriginal Matrix\n");
for(i=1;i<=a[0].v;i++)
printf("%d\t%d\t%d\n",a[i].r,a[i].c,a[i].v);
transpose(a,t);
printf("\nTranspose Matrix\n");
for(i=1;i<=t[0].v;i++)
printf("%d\t%d\t%d\n",t[i].r,t[i].c,t[i].v);
return 0;
}