‘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

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.