C++ Online Compiler
Example: Lower Triangular Matrix example in C++ using for loop
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Lower Triangular Matrix example in C++ for loop #include <bits/stdc++.h> #define size 4 using namespace std; // @Utility function to check lower triangular matrix int CheckLowerTriangularMatrix(int matrix[size][size]) { int i, j; for (i = 0; i < size; i++) for (j = i + 1; j < size; j++) if (matrix[i][j] != 0) return 0; return 1; } // @Driver function to run the program int main() { int matrix[size][size], i, j; cout << "The Size of the matrix is: " << size << endl; cout << "\nEnter the matrix's elements:\n"; for(i = 0; i < size; i++) { for(j = 0; j < size; j++) cin >> matrix[i][j]; cout << endl; } if (CheckLowerTriangularMatrix(matrix)) cout << "This is the Lower Triangular Matrix.\n"; else cout << "This not a Lower Triangular Matrix!\n"; return 0; }
4 0 0 0 0 1 0 0 0 1 2 0 0 1 2 3 0
Output
Clear
ADVERTISEMENTS