C PROGRAM TO CHECK MATRIX IS UPPER OR LOWER OR TRIDIAGONAL MATRIX
#include<stdio.h>
#define n 4
int main()
{
int a[n][n],i,j,cnt=0,f=0,g=0,k=0,l=0,m=0;
float z=0;
printf("enter the elements of the matrix:-\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]==0)
cnt=cnt+1;
}
}
printf("%d\n",cnt);
z=(cnt*100)/(n*n);
printf("%f\n",z);
if(z>=(n*n)/2)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if((i<j) && a[i][j]!=0)
f=1;
else if((i>j) && a[i][j]!=0)
g=1;
}
}
if(f==1 && g!=1)
printf("lower triangular sparse matrix");
else if(f!=1 && g==1)
printf("upper triangular sparse matrix");
else
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if((i==j) && a[i][j]!=0)
k=1;
if((i+1==j) && a[i][j]!=0)
l=1;
if((i==j+1) && a[i][j]!=0)
m=1;
}
}
if(k==1 && l==1 && m==1)
printf("tridiagnol sparse matrix");
}
}
else printf("not a sparse matrix");
return 0;
}
OUTPUT:-
In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.
#include<stdio.h>
#define n 4
int main()
{
int a[n][n],i,j,cnt=0,f=0,g=0,k=0,l=0,m=0;
float z=0;
printf("enter the elements of the matrix:-\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]==0)
cnt=cnt+1;
}
}
printf("%d\n",cnt);
z=(cnt*100)/(n*n);
printf("%f\n",z);
if(z>=(n*n)/2)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if((i<j) && a[i][j]!=0)
f=1;
else if((i>j) && a[i][j]!=0)
g=1;
}
}
if(f==1 && g!=1)
printf("lower triangular sparse matrix");
else if(f!=1 && g==1)
printf("upper triangular sparse matrix");
else
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if((i==j) && a[i][j]!=0)
k=1;
if((i+1==j) && a[i][j]!=0)
l=1;
if((i==j+1) && a[i][j]!=0)
m=1;
}
}
if(k==1 && l==1 && m==1)
printf("tridiagnol sparse matrix");
}
}
else printf("not a sparse matrix");
return 0;
}
OUTPUT:-
In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.
No comments:
Post a Comment