Here we can take the string and reverse it. Then compare the original string with the reversed string. If they are the same then it is a palindrome.

__________________________________________________________________

Write a program that will take a number in integer format and convert it and print it in string format. For e.g.,

Input Integer => 574
Output String => “574”

Solution 1 ( using sprintf )

/* sprint usage is just like printf. Instead of printing the value on the console we print the value into a string ( char array ).

printf => Print on Console

fprintf => Print into a file

sprint => Print into a string

*/

#include <stdio.h>

#include <string.h>

int main()

{

int number, nitems;

char clear[25];

char token[25];

printf(“\nPlease enter a number :”);

fflush(stdin);

nitems = scanf(“%d”, &number);

while ( nitems != 1 ){

/* Clear the Buffer */

gets(clear);

printf(“\nPlease enter a number – digits only :”);

nitems = scanf(“%d”, &number);

}

printf(“\nThe number of items scanned = %d”, nitems);

sprintf(token, “%d”, number);

printf(“\nThe number %d is converted into string : %s\n”, number, token);

}

Solution 2 ( using integer manipulation )

#include <stdio.h>

#include <string.h>

int main() {

int number, temp, j = 0, i, rem;

char token[25], snumber[25];

printf(“\nPlease enter a number :”);

scanf(“%d”, &number);

temp = number;

while ( temp ) {

rem = temp%10;

temp = temp/10;

token[j++] = (char)(rem + 48);

}

token[j] = ‘\0’; /* Token Array has the value “427” */

i = 0;

/* Here we are reversing the array, i.e., 427 to 724 */

for ( j=strlen(token)-1; j>=0; j– ){

snumber[i++] = token[j];

}

snumber[i] = ‘\0’;

printf(“\nThe number %d is converted into string : %s\n”, number,

snumber);

}