next palindrome number in cpp

Solutions on MaxInterview for next palindrome number in cpp by the best coders in the world

showing results for - "next palindrome number in cpp"
Oskar
19 Sep 2016
1#include <iostream>
2
3
4bool isPalindrome (int number) {
5    int decomposed = number, reversed = 0;
6    while (decomposed) {
7        reversed = 10 * reversed + (decomposed % 10);
8        decomposed /= 10;
9    }
10    return reversed == number;
11}
12
13
14int nextPalindromicNumber (int number) {
15    while (!isPalindrome(++number));
16    return number;
17}
18
19
20int main () {
21    int testCases;
22    std::cin >> testCases;
23    while (testCases--) {
24        int number;
25        std::cin >> number;
26        std::cout << nextPalindromicNumber(number) << '\n';
27    }
28}
29
Marie
28 Jan 2019
1#include <iostream>
2#include <string.h>
3using namespace std;
4int nextpalin (int num){
5    while (num++) {
6        string str = to_string (num); /// int to string conversion
7        int l = str.length()-1;
8        int s = 0;
9        while( s<l ){
10              if (str[s]!=str[l]) break;
11              else {
12                    s++;
13                    l--;
14                    }
15        if (s>=l) return num;}
16                }
17   }
18
19int main () {
20    int t;
21    cin >> t;
22    while (t--){
23    int num;
24    cin >> num;
25    if (num==0)  cout << "1" << endl;
26   else { 
27       if (num<9)  cout << num+1 << endl;
28       else  cout << nextpalin( num) << endl;}
29     }
30}
31
queries leading to this page
how to print palindrome number in c 2b 2bc 2b 2b palindromes less than a given numberpalindrome program in cpppalindrome program in c 2b 2bpalindrome integer c 2b 2bcheck user input for palindrome in cppc 2b 2b find palindromec 2b 2b palindrome programin c 2b 2b write a function of palindromenumber palindrome or not cpppalindrome in c 2b 2bc 2b 2b program to find palindrome numberhow to use next palindrome in c 2b 2bpalindrome logic in cppc 2b 2b functions palindromepalindrome numbers in c 2b 2bpalindrome number program in cpphow do you palindrome in c 2b 2b 3fcalculate palindrome number c 2b 2bmake palindrome not palindrome cpppalindrome using cppc 2b 2b palindromepalindrome cpp programstack and queue palindrome c 2b 2bis palindrome function c 2b 2bpalindrome numbers c 2b 2bhow to use next palindrome in c 2b 2b stringc 2b 2b program to find a palindromehow to make a palindrome in c 2b 2bc 2b 2b palindrome number programpalidrome numbers c 2b 2bmake a number palindrom number cpppalindrom c 2b 2b codec 2b 2b program for palindrome numberpalindrome in c 2b 2bhow to find palindrome in c 2b 2bpalindrome string cppprogram for palindrome in of number c 2b 2bperfect palindrome in c 2b 2bpalindromes examples cpppalindrome number in cppc 2b 2b palindrome functionfind palindrome c 2b 2bpalindrome number c 2b 2b programmake palindrome c 2b 2bcheck palindrome function in cpppalindrome number in c 2b 2b using functionpalindrome number in c 2b 2bpalindrome number code c 2b 2bpalindrome of a number c 2b 2bpalindrome solution in cppc 2b 2b program to find palindromec 2b 2b program palindromepalindrome number using c 2b 2bc 2b 2b is palindromefind palindrom number in c 2b 2bpalindrome function cpppalindrome code in c 2b 2bpalindrome in cpphow to check for palindrome in c 2b 2bfunction to check palindrome in c 2b 2bcpp program to find palindromehow to find all possible palindromes in c 2b 2bwrite a program to print palindrome in c 2b 2bpalindrome n c 2b 2bnumber palindrome c 2b 2bmake palindrome from string in cpppalindrome function in c 2b 2bhow t find a palindrome in cppstring palindrome in cpppalindrome int c 2b 2bc 2b 2b program for palindromecode for palindrome in cpppalindrome c 2b 2b number 5cpalindrome number cpppalindrome inbuilt function in cppnumbers palindrome series in c 2b 2bpalindrome number c 2b 2bpalindrome of a number cpppalindrome in cpp geeksforgeeks palindrome c 2b 2bpalindrome cpppalindrome c 2b 2bc 2b 2b program palindrome using functionnext palindrome number in cpp