C++ Online Compiler
Example: Upper Triangular Matrix example in C++ using for loop
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Upper Triangular Matrix example in C++ using for loop #include <bits/stdc++.h> using namespace std; int main() { int size, flag = 0, i, j; cout << "Enter the size of the matrix: "; cin >> size; int matrix[size][size]; 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; } for (i = 1; i < size; i++) { for (j = 0; j < i; j++) { if (matrix[i][j] != 0) flag = 0; else flag = 1; } } if (flag == 1) cout << "This is the Upper Triangular Matrix.\n"; else cout << "This not an Upper Triangular Matrix!\n"; return 0; }
4 0 2 3 4 0 0 2 3 0 0 0 2 0 0 0 0
Output
Clear
ADVERTISEMENTS