How to find nth palindrome number using C?
Example: 0-9 is palindrome, 11 is 11th palindrome, 22 is 12th palindrome, and so on.
#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; }
To do this, you have to follows two rules:
for example: for string abc abc->abb->aba total 2 number of operations needed to make it a palindrome.
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.