Wednesday, July 6, 2011

Program to find whether the given number is a Palindrome or not using functions.


#include<iostream.h>
#include<conio.h>
int palindrome(int num)
{
       int c=0,i,f=0;
       int ar[100];
       for(i=0;i<100;i++)
       {
    ar[i]=0;
       }
       while(num>0)
       {
      ar[c]=num%10;
      c++;
      num/=10;
       }
       for(i=0;i<((c-1)/2);i++)
       {
    if(ar[i]!=ar[c-i-1])
    {
      f=1;
      break;
    }
       }
       return f;
}
void main()
{
  clrscr();
  int n,p;
  cout<<"Enter the number: "<<endl;
  cin>>n;
  p=palindrome(n);
  cout<<"The number is"<<endl;
  if(p==1)
      cout<<" not a palindrome"<<endl;
  else
      cout<<" a palindrome"<<endl;
  getch();
}

No comments:

Post a Comment