//Program to create lower triangular matrix.
#include<stdio.h>
#include<conio.h>
void create(int **t,int n,int r);
void print(int *t,int n);
main()
{
int *a,ele,r;
printf("how many rows you want in lower triangular matrix :");
scanf("%d",&r);
ele=(r*(r+1))/2;
create(&a,ele,r);
print(a,r);
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]);
}
}
}
#include<stdio.h>
#include<conio.h>
void create(int **t,int n,int r);
void print(int *t,int n);
main()
{
int *a,ele,r;
printf("how many rows you want in lower triangular matrix :");
scanf("%d",&r);
ele=(r*(r+1))/2;
create(&a,ele,r);
print(a,r);
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]);
}
}
}