‘C’ program to check if a matrix is upper triangular.
C File =>
/* Write a ‘C’ program to check if a matrix is upper triangular. */
#include<stdio.h>
int main()
{
int i,j,r,c,mat[30][30],flag=1;
printf("\n Enter number of rows in matrix : ");
scanf("%d",&r);
printf("\n Enter number of cols in matrix : ");
scanf("%d",&c);
//Accepting matrix
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("\n Enter matrix element : ");
scanf("%d",&mat[i][j]);
}
}
//checking upper triangular
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(r>c && mat[i][j]!=0)
{
flag=0;
break;
}
}
}
if(flag==0)
printf("\n Matrix is NOT upper triangular..");
else
printf("\n Matrix is upper triangular.. ");
return 0;
}
Comments
Post a Comment
Please do not enter any spam link in message.