Sum of all N digit palindromic numbers divisible by 9 formed using digits 1 to 9 | C ++ implementation to find the sum of all the N digit palindromic numbers divisible by 9 ; Function for finding count of N digits palindrome which are divisible by 9 ; if N is odd ; if N is even ; Function for finding sum of N digits palindrome which are divisible by 9 ; count the possible number of palindrome ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countPalindrome ( int n ) { int count ; if ( n % 2 == 1 ) { count = pow ( 9 , ( n - 1 ) / 2 ) ; } else { count = pow ( 9 , ( n - 2 ) / 2 ) ; } return count ; } int sumPalindrome ( int n ) { int count = countPalindrome ( n ) ; int res = 0 ; if ( n == 1 ) return 9 ; if ( n == 2 ) return 99 ; for ( int i = 0 ; i < n ; i ++ ) { res = res * 10 + count * 5 ; } return res ; } int main ( ) { int n = 3 ; cout << sumPalindrome ( n ) ; return 0 ; }