Code
#include
#define MAX_ROWS 3
#define MAX_COLS 3
int main()
{
int array[MAX_ROWS][MAX_COLS];
int row, col, isUpper;
/* Input elements in matrix from user */
printf("Enter elements in matrix of size %dx%d: \n", MAX_ROWS, MAX_COLS);
for(row=0; row
{
for(col=0; col
{
scanf("%d", &array[row][col]);
}
}
/* Check Upper triangular matrix condition */
isUpper = 1;
for(row=0; row
{
for(col=0; col
{
/*
* If elements below the main diagonal (col
* is not equal to zero then it is not upper triangular matrix
*/
if(col
{
isUpper = 0;
}
}
}
/* Print elements of upper triangular matrix */
if(isUpper == 1)
{
printf("\nThe matrix is Upper triangular matrix.\n");
for(row=0; row
{
for(col=0; col
{
printf("%d ", array[row][col]);
}
printf("\n");
}
}
else
{
printf("\nThe matrix is not Upper triangular matrix.");
}
return 0;
}
Output
More C programs