C program to check given number is palindrome or not

 

C program to check given number is palindrome or not


/***********************************************

C program to check given number is palindrome or not

For example, 

N= 121                                                    N=123

Reverse=121                                            Reverse=321

Given number is palindrome                    Number is not palindrome

**********************************************/

# include<stdio.h>

#include<conio.h>

void main()

{

    int n,rem,temp,sum=0;

    clrscr();

    printf("Enter number\n");

    scanf("%d",&n);

    printf("The reverse order of given number is: ");

    temp=n;

    while(n!=0)

    {

        rem=n%10;

        sum=(sum*10)+rem;

        printf("%d",rem);

        n=n/10;

        

    }

    if(sum==temp)

    printf("\nThe reverse number and original number are same so the number %d is Palindrome\n",temp);

    else

    printf("\nThe reverse number and original number are not same so the number %d is  Not palindrome",temp);

}

Enter number

123

The reverse order of given number is: 321

The reverse number and original number are not same so the number 123 is  Not palindrome



Enter number

131

The reverse order of given number is: 131

The reverse number and original number are same so the number 131 is Palindrome


टिप्पणी पोस्ट करा

0 टिप्पण्या