-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathTriangularMatrix.c
63 lines (62 loc) · 1.88 KB
/
TriangularMatrix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/******************************************************
* File : MatrixAddidion.c
* Description : C Program to find the matrix is a triangular matrix or not
* Author : Sarju S
* Version : 1.0
* Date : 09/08/2021
* ***************************************************/
#include<stdio.h>
int main(){
int myMatrix[10][10];
int size,row,col,isLowerTriangle=1,isUpperTriangle=1;
printf("\nEnter the number of rows/colums of the given square matrix:");
scanf("%d",&size);
printf("\nEnter the elements\n");
for(row=0;row<size;row++){
for(col=0;col<size;col++){
printf("MyMatrix[%d][%d]::",row,col);
scanf("%d",&myMatrix[row][col]);
}
}
printf("\nThe given Matrix is:\n");
for(row=0;row<size;row++){
for(col=0;col<size;col++){
printf("%d\t",myMatrix[row][col]);
}
printf("\n");
}
//Lower Triangle and Upper Triangle Checking
for(row=0;row<size;row++){
for(col=0;col<size;col++){
if(col>row){
if(myMatrix[row][col]!=0){
isLowerTriangle = 0;
}
}
if(row>col){
if(myMatrix[row][col]!=0){
isUpperTriangle = 0;
}
}
}
}
if(isLowerTriangle==1){
printf("\nThe given matrix is a Lower Triangle Matrix");
}
else{
printf("\nThe given matrix is not a Lower Triangle Matrix");
}
if(isUpperTriangle==1){
printf("\nThe given matrix is a Upper Triangle Matrix");
}
else{
printf("\nThe given matrix is not a Upper Triangle Matrix");
}
if(isLowerTriangle==1 || isUpperTriangle ==1){
printf("\nThe given matrix is a triangular matrix");
}
else{
printf("\nThe given matrix is not a triangular matrix");
}
return 0;
}