//Program to find the multiplication of two lower triangular matrixs.
#include<stdio.h>
#include<conio.h>
void create(int **t,int n,int r);
void print(int *t,int n);
void mul(int *a,int *b,int *c,int m);
int sear(int *t,int i,int j);
main()
{
int *a,*b,*c,ele,m,n,ele1,i,j;
printf("how many rows you want in first lower triangular matrix :");
scanf("%d",&m);
ele=(m*(m+1))/2;
create(&a,ele,m);
printf("how many rows you want in second lower triangular matrix :");
scanf("%d",&n);
ele1=(n*(n+1))/2;
create(&b,ele1,n);
printf("\n1st matrix \n");
print(a,m);
printf("\n2nd matrix \n");
print(b,n);
if(m==n)
{
c=(int *)malloc(m*sizeof(int));
mul(a,b,c,m);
printf("multiplication of two lower triangle matrix is:");
print(c,m);
}
else
printf("multiplication not possoble");
getch();
}
void create(int **t,int n,int r)
{
int p,q,i,j,k,*a,*b,m=0,f,c=0;
printf("\nEnter the element of lower triangular matrix");
a=(int*)malloc(n*sizeof(int));
b=(int*)malloc(n*sizeof(int));
for(p=0;p<n;p++)
{
f=0;
printf("\nEnter the postion row and column of element:");
scanf("%d%d",&i,&j);
if(j>i||i>=r)
{
printf("\nYou have entered the wrong poition of element.Try again");
p=p-1;
continue;
}
k=(i*(i+1))/2+j;
for(q=0;q<m;q++)
{
if(b[q]==k)
{
f=1;
break;
}
}
if(f==1)
{
printf("\nAt the given postion you already entered the data. Do you want to override it? if YES press 1 if NO press 0");
scanf("%d",&c);
p=p-1;
if(c==1)
{
printf("\nEnter the value: ");
scanf("%d",&a[k]);
continue;
}
else
continue;
}
b[m]=k;
m++;
printf("\nEnter the value: ");
scanf("%d",&a[k]);
}
*t=a;
}
void print(int *t,int n)
{
int i,j,k;
for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<=i;j++)
{
k=(i*(i+1))/2+j;
printf("%d ",t[k]);
}
}
}
void mul(int *a,int *b,int *c,int m)
{
int i,j,k,p;
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
if(j>i)
break;
p=(i*(i+1))/2+j;
c[p]=0;
for(k=0;k<m;k++)
c[p]+=sear(a,i,k)*sear(b,k,j);
}
}
}
int sear(int *t,int i,int j)
{
int k;
if(j>i)
return 0;
k=(i*(i+1))/2+j;
return (t[k]);
}
#include<stdio.h>
#include<conio.h>
void create(int **t,int n,int r);
void print(int *t,int n);
void mul(int *a,int *b,int *c,int m);
int sear(int *t,int i,int j);
main()
{
int *a,*b,*c,ele,m,n,ele1,i,j;
printf("how many rows you want in first lower triangular matrix :");
scanf("%d",&m);
ele=(m*(m+1))/2;
create(&a,ele,m);
printf("how many rows you want in second lower triangular matrix :");
scanf("%d",&n);
ele1=(n*(n+1))/2;
create(&b,ele1,n);
printf("\n1st matrix \n");
print(a,m);
printf("\n2nd matrix \n");
print(b,n);
if(m==n)
{
c=(int *)malloc(m*sizeof(int));
mul(a,b,c,m);
printf("multiplication of two lower triangle matrix is:");
print(c,m);
}
else
printf("multiplication not possoble");
getch();
}
void create(int **t,int n,int r)
{
int p,q,i,j,k,*a,*b,m=0,f,c=0;
printf("\nEnter the element of lower triangular matrix");
a=(int*)malloc(n*sizeof(int));
b=(int*)malloc(n*sizeof(int));
for(p=0;p<n;p++)
{
f=0;
printf("\nEnter the postion row and column of element:");
scanf("%d%d",&i,&j);
if(j>i||i>=r)
{
printf("\nYou have entered the wrong poition of element.Try again");
p=p-1;
continue;
}
k=(i*(i+1))/2+j;
for(q=0;q<m;q++)
{
if(b[q]==k)
{
f=1;
break;
}
}
if(f==1)
{
printf("\nAt the given postion you already entered the data. Do you want to override it? if YES press 1 if NO press 0");
scanf("%d",&c);
p=p-1;
if(c==1)
{
printf("\nEnter the value: ");
scanf("%d",&a[k]);
continue;
}
else
continue;
}
b[m]=k;
m++;
printf("\nEnter the value: ");
scanf("%d",&a[k]);
}
*t=a;
}
void print(int *t,int n)
{
int i,j,k;
for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<=i;j++)
{
k=(i*(i+1))/2+j;
printf("%d ",t[k]);
}
}
}
void mul(int *a,int *b,int *c,int m)
{
int i,j,k,p;
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
if(j>i)
break;
p=(i*(i+1))/2+j;
c[p]=0;
for(k=0;k<m;k++)
c[p]+=sear(a,i,k)*sear(b,k,j);
}
}
}
int sear(int *t,int i,int j)
{
int k;
if(j>i)
return 0;
k=(i*(i+1))/2+j;
return (t[k]);
}