Count the number of digits of palindrome numbers in an array | C ++ implementation of the approach ; Function to return the reverse of n ; Function that returns true if n is a palindrome ; Function to return the count of digits of n ; Function to return the count of digits in all the palindromic numbers of arr [ ] ; If arr [ i ] is a one digit number or it is a palindrome ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int reverse ( int n ) { int rev = 0 ; while ( n > 0 ) { int d = n % 10 ; rev = rev * 10 + d ; n = n / 10 ; } return rev ; } bool isPalin ( int n ) { return ( n == reverse ( n ) ) ; } int countDigits ( int n ) { int c = 0 ; while ( n > 0 ) { n = n / 10 ; c ++ ; } return c ; } int countPalinDigits ( int arr [ ] , int n ) { int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 10 || isPalin ( arr [ i ] ) ) { s += countDigits ( arr [ i ] ) ; } } return s ; } int main ( ) { int arr [ ] = { 121 , 56 , 434 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << ( countPalinDigits ( arr , n ) ) ; return 0 ; }