top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find nth palindrome number using C?

+1 vote
2,226 views

How to find nth palindrome number using C?

Example:
0-9 is palindrome,
11 is 11th palindrome,
22 is 12th palindrome,
and so on.

posted Jun 6, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
#include<stdio.h>
    int check_palin(int num)
    {
      int n1 = num;
      int rev = 0;
      while (n1){
            rev = (rev * 10)+(n1 % 10);
            n1 = n1 / 10;
      }
      if (rev == num)
            return 1;
      else
            return 0;
    }


    int main()
    {
      int i = 0;
      int count = 0;
      int n; /* nth palindrome that needs to be found out 
                 the value of n should be greater then 0*/
      printf("Enter the value of n[n > 0]\n ");
      scanf("%d",&n);
      while (count != n){
            if (check_palin(i)){
                 count++;
            }
            i++;
      }
      printf("%dth Palindrome is %d\n", n, i-1);
      return 0;
    }
answer Jun 6, 2016 by Lavanya L
Similar Questions
+4 votes

To do this, you have to follows two rules:

  1. You can reduce the value of a letter, e.g. you can change d to c, but you cannot change c to d.
  2. In order to form a palindrome, if you have to repeatedly reduce the value of a letter, you can do it until the letter becomes a. Once a letter has been changed to a, it can no longer be changed.

for example: for string abc
abc->abb->aba
total 2 number of operations needed to make it a palindrome.

+5 votes

Help me to write a C program which can generate list of numbers which are palindrome in decimal and octal notion. You can take some max as a limit find out all numbers which satisfy the given property between 1 to n.

...