Program for Markov matrix | C ++ code to check Markov Matrix ; outer loop to access rows and inner to access columns ; Find sum of current row ; Driver Code ; Matrix to check ; calls the function check ( )
#include <iostream> NEW_LINE using namespace std ; #define n  3 NEW_LINE bool checkMarkov ( double m [ ] [ n ] ) { for ( int i = 0 ; i < n ; i ++ ) { double sum = 0 ; for ( int j = 0 ; j < n ; j ++ ) sum = sum + m [ i ] [ j ] ; if ( sum != 1 ) return false ; } return true ; } int main ( ) { double m [ 3 ] [ 3 ] = { { 0 , 0 , 1 } , { 0.5 , 0 , 0.5 } , { 1 , 0 , 0 } } ; if ( checkMarkov ( m ) ) cout << " ▁ yes ▁ " ; else cout << " ▁ no ▁ " ; }