You are on page 1of 2

PROGRAM CODE :

#include<stdio.h>
#include<stdlib.h>
struct smarray
{
int r,c,v;
};
int main()
{
struct smarray *a,*b;
int i,r1,c1,t,j,pb=0;
printf("\nenter the no. of rows:");
scanf("%d",&r1);
printf("\nenter the no. of columns:");
scanf("%d",&c1);
printf("\nenter the no. of terms:");
scanf("%d",&t);
a=(struct smarray*)malloc(sizeof(struct smarray)*t);
b=(struct smarray*)malloc(sizeof(struct smarray)*t);
for(i=0;i<t;i++)
{
printf("\nenter %d term r , c , v :",(i+1));
scanf("%d%d%d",&a[i].r,&a[i].c,&a[i].v);
}
printf("\nentered array is :\n");
printf(" r c v \n");
for(i=0;i<t;i++)

printf(" %d %d %d \n ",a[i].r,a[i].c,a[i].v);
for(i=0;i<c1;i++)
{
for(j=0;j<t;j++)
{
if(a[j].c==i)
{
b[pb].r=a[j].c;
b[pb].c=a[j].r;
b[pb].v=a[j].v;
pb++;
}
}
}
printf("\ntranspose of array is :\n");
printf(" r c v \n");
for(i=0;i<t;i++)
printf(" %d %d %d \n",b[i].r,b[i].c,b[i].v);
return 0;
}
OUTPUT:
enter the no. of rows:3
enter the no. of columns:3
enter the no. of terms:4
enter 1 term r , c , v :0
0
4
enter 2 term r , c , v :1
0
1
enter 3 term r , c , v :2
0
1
enter 4 term r , c , v :2
1
3
entered array is :
r c v
0 0 4
1 0 1
2 0 1
2 1 3
transpose of array is :
r c v
0 0 4
0 1 1
0 2 1
1 2 3
Process returned 0 (0x0) execution time : 125.437 s
Press any key to continue.