Blog Moved

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Search This Blog

15 Aug 2012

C Program To Find The Number Palindrome or Not


/* To Find Whether Number is Palindrome or Not */
#include<stdio.h>
//#include<conio.h>
void main()
{
    int num,rem,sum=0,temp;
    //clrscr();
    printf("\n /** To Find Reverse Of a Number **/ \n");
    printf("\n Enter a number: ");
    scanf("%d",&num);
    temp=num;
    while(num)
    {
     rem=num%10;  //for getting remainder by dividing with 10
     num=num/10; //for getting quotient by dividing with 10
     sum=sum*10+rem; /*multiplying the sum with 10 and adding
                           remainder*/
    }
    printf("\n The Reversed Number is: %d \n",sum);
    if(temp==sum) //checking whether the reversed number is
                    equal to entered number
    {
      printf("\n Number is Palindrome \n\n" );
    }
    else
    {
      printf("\n Number is not a palindrome \n\n");
    }
    //getch();
    return 0;
}


Sample Output:( using GNU GCC Compiler with code::blocks IDE, hence no need of clrscr(); and getch(); )



2 comments: