Check whether the number can be made palindromic after adding K | C ++ program to check whether the number can be made palindrome number after adding K ; Function to check whether a number is a palindrome or not ; Convert num to string ; Comparing kth character from the beginning and N - kth character from the end . If all the characters match , then the number is a palindrome ; If all the above conditions satisfy , it means that the number is a palindrome ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void checkPalindrome ( int num ) { string str = to_string ( num ) ; int l = 0 , r = str . length ( ) - 1 ; while ( l < r ) { if ( str [ l ] != str [ r ] ) { cout << " No " ; return ; } l ++ ; r -- ; } cout << " Yes " ; return ; } int main ( ) { int n = 19 , k = 3 ; checkPalindrome ( n + k ) ; return 0 ; }