Print Upper Hessenberg matrix of order N | C ++ implementation of the approach ; Function to print the Upper Hessenberg matrix of order n ; If element is below sub - diagonal then print 0 ; Print a random digit for every non - zero element ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void UpperHessenbergMatrix ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( i > j + 1 ) cout << '0' << " ▁ " ; else cout << rand ( ) % 10 << " ▁ " ; } cout << " STRNEWLINE " ; } } int main ( ) { int n = 4 ; UpperHessenbergMatrix ( n ) ; return 0 ; }