RUN


Here, We’ll learn to write a program to check whether the given matrix is upper triangular or not in C programming language.

Upper Triangular Matrix: A matrix is known as an upper triangular matrix if all the values below diagonal are 0.

Source: https://commons.wikimedia.org/wiki/File:Triangular_matrix.svg

Code:

#include <stdio.h>
 
int main (){
 
  int n, i, j, is_uppr=1, is_lowr=1, a;
 
  printf("Enter the number of rows:: ");
  scanf("%d",&n);
 
  printf("Enter the Array::\n");
  for( i=0; i<n; i++){
    for( j=0; j<n; j++){
      scanf("%d",&a);
      if( j>i && a!=0)//Check for upper triangular condition
    is_uppr = 0;
      if( j<i && a!=0)//Check for lower triangular condition
    is_lowr = 0;
    }
  }
  if( is_uppr==1 || is_lowr==1)
    printf("Upper Triangular\n");
  else
    printf("Not Upper Triangular\n");
 
  return 0;
 
}

Report Error/ Suggestion

Related Posts:




CopyRight © 2020

CopyRight © 2020