Count digits present in each element of a given Matrix | C ++ program for the above approach ; Function to count the number of digits in each element of the given matrix ; Traverse each row of arr [ ] [ ] ; Traverse each column of arr [ ] [ ] ; Store the current matrix element ; Count the number of digits ; Print the result ; Driver Code ; Given matrix
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int M = 3 ; const int N = 3 ; void countDigit ( int arr [ M ] [ N ] ) { for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { int X = arr [ i ] [ j ] ; int d = floor ( log10 ( X ) * 1.0 ) + 1 ; cout << d << " ▁ " ; } cout << endl ; } } int main ( ) { int arr [ ] [ 3 ] = { { 27 , 173 , 5 } , { 21 , 6 , 624 } , { 5 , 321 , 49 } } ; countDigit ( arr ) ; return 0 ; }