text: Generate number with given operation and check if it is palindrome | C # implementation of the approach ; Function that returns true if str is a palindrome ; Function that returns true if the generated string is a palindrome ; sub contains N as a string ; Calculate the sum of the digits ; Repeat the substring until the length of the resultant string < sum ; If length of the resultant string exceeded sum then take substring from 0 to sum - 1 ; If the generated string is a palindrome ; Driver code
code: using System ; class GFG { static bool isPalindrome ( string str ) { int len = str . Length ; for ( int i = 0 ; i < len / 2 ; i ++ ) { if ( str [ i ] != str [ len - 1 - i ] ) return false ; } return true ; } static bool createStringAndCheckPalindrome ( int N ) { string sub = " " + N , res_str = " " ; int sum = 0 ; while ( N > 0 ) { int digit = N % 10 ; sum += digit ; N = N / 10 ; } while ( res_str . Length < sum ) res_str += sub ; if ( res_str . Length > sum ) res_str = res_str . Substring ( 0 , sum ) ; if ( isPalindrome ( res_str ) ) return true ; return false ; } public static void Main ( ) { int N = 10101 ; if ( createStringAndCheckPalindrome ( N ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }