#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int z1[3],z2[3],z3[3],p2=0,p1=0,r[3],q[3],v[3],r1,r2,c1,c2,i,j,a[10][10],b[10][10],c[10][10],sp[10][3];
clrscr();
printf("enter no of row of the matrix A : ");
scanf("%d",&r1);
printf("enter no of column of the matrix A ");
scanf("%d",&c1);
printf("enter no of row of the matrix B : ");
scanf("%d",&r2);
printf("enter no of column of the matrix B : ");
scanf("%d",&c2);
printf("enter element in matrix A : ");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter element in matrix B : ");
for(i=1;i<=r2;i++)
{
for(j=1;j<=c2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("Display matrix A\n");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("Display matrix B\n");
for(i=1;i<=r2;i++)
{
for(j=1;j<=c2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
if(r1==r2&&c1==c2)
{
printf("addtion of matrix A & B & Display matrix C\n");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("%d\t",c[i][j]);
if(c[i][j]!=0)
{
r[p1]=i;
q[p1]=j;
v[p1]=c[i][j];
p1++;
}
}
printf("\n");
}
}
printf("total non zero element in matrix C %d & Display its sparse matrix\n",p1);
for(i=0;i<p1;i++)
{
printf("%d\t",r[i]);
printf("%d\t",q[i]);
printf("%d\n",v[i]);
}
printf(" transpose of A\n");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
printf("%d\t",a[j][i]);
} printf("\n");
}
for(i=1;i<4;i++)
{
for(j=1;j<4;j++)
{
if(a[j][i]!=0)
{
z1[p2]=i;
z2[p2]=j;
z3[p2]=a[j][i];
p2++;
}
}
}
printf("non zero element in transpose of A %d & Display its sparse matrix\n",p2);
for(i=0;i<p2;i++)
{
printf("%d\t",z1[i]);
printf("%d\t",z2[i]);
printf("%d\n",z3[i]);
}
getch();
}
Output :
#include<conio.h>
#include<stdlib.h>
void main()
{
int z1[3],z2[3],z3[3],p2=0,p1=0,r[3],q[3],v[3],r1,r2,c1,c2,i,j,a[10][10],b[10][10],c[10][10],sp[10][3];
clrscr();
printf("enter no of row of the matrix A : ");
scanf("%d",&r1);
printf("enter no of column of the matrix A ");
scanf("%d",&c1);
printf("enter no of row of the matrix B : ");
scanf("%d",&r2);
printf("enter no of column of the matrix B : ");
scanf("%d",&c2);
printf("enter element in matrix A : ");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter element in matrix B : ");
for(i=1;i<=r2;i++)
{
for(j=1;j<=c2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("Display matrix A\n");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("Display matrix B\n");
for(i=1;i<=r2;i++)
{
for(j=1;j<=c2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
if(r1==r2&&c1==c2)
{
printf("addtion of matrix A & B & Display matrix C\n");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("%d\t",c[i][j]);
if(c[i][j]!=0)
{
r[p1]=i;
q[p1]=j;
v[p1]=c[i][j];
p1++;
}
}
printf("\n");
}
}
printf("total non zero element in matrix C %d & Display its sparse matrix\n",p1);
for(i=0;i<p1;i++)
{
printf("%d\t",r[i]);
printf("%d\t",q[i]);
printf("%d\n",v[i]);
}
printf(" transpose of A\n");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
printf("%d\t",a[j][i]);
} printf("\n");
}
for(i=1;i<4;i++)
{
for(j=1;j<4;j++)
{
if(a[j][i]!=0)
{
z1[p2]=i;
z2[p2]=j;
z3[p2]=a[j][i];
p2++;
}
}
}
printf("non zero element in transpose of A %d & Display its sparse matrix\n",p2);
for(i=0;i<p2;i++)
{
printf("%d\t",z1[i]);
printf("%d\t",z2[i]);
printf("%d\n",z3[i]);
}
getch();
}
Output :
output screen |
0 comments:
Post a Comment
Comments : Read Them Or Add One to promote us