Code Scrappers


Palindrome C program


                    #include<stdio.h>
                    #include<stdlib.h>

                    int main()
                    {
                        int n, reversednum = 0, remainder, originalnum;

                        printf("Enter an integer: ");

                        scanf("%d", &n);

                        originalnum = n;

                         while( n!=0 )
                         {
                             remainder = n%10;

                             reversednum = reversednum*10 + remainder;

                             n /= 10;

                         }

                        if (originalnum == reversednum)
                        {
                            printf("%d is a palindrome.", originalnum);
                        }
                        else
                        {
                            printf("%d is not a palindrome.", originalnum);
                        }
                    }



                



Output

          Enter an integer: 252
          252 is a palindrome.