C Code 21 _ To find whether the given number is palindrome or not if not then check whether the number can be made to palindrome by changing its positions



C Code 21 _ To find whether the given number is palindrome or not if not then check whether the number can be made to palindrome by changing its positions

Program:



#include<stdio.h>
int main()
{
                int n,r,rev=0,t,l=0,j,i,v=0;
                int a[10]={0,0,0,0,0,0,0,0,0,0};
                printf("\nEnter a number : ");
                scanf("%d",&n);
                t=n;
                while(n>0)
                {
                                r=n%10;
                                a[r]=a[r]+1;
                                rev=(rev*10)+r;
                                n=n/10;
                                l=l+1;
                }
                printf("\nLength of number : %d",l);
                //printf("\n\n");
                //for(i=0;i<10;i++)
                //{
                //            printf("%d ",a[i]);
                //}
                if(t==rev)
                {
                                printf("\n\nThe given number is a palindrome");
                }
                else
                {
                                if(l%2==0)
                                {
                                                for(i=0;i<10;i++)
                                                {
                                                                if((a[i]!=0)&&(a[i]%2==0))
                                                                {
                                                                                v=v+1;
                                                                }
                                                }
                                                if((v*2)==(l))
                                                {
                                                                printf("\n\nThe given number is not a palindrome.But it can be changed in to palindrome");
                                                }
                                                else
                                                {
                                                                printf("\n\nThe given number is not a palindrome.And it cannot be changed in to palindrome");
                                                }
                                }
                                else
                                {
                                                for(i=0;i<l;i++)
                                                {
                                                                if((a[i]!=0)&&(a[i]%2==0))
                                                                {
                                                                                v=v+1;
                                                                }
                                                }
                                                if((v*2)==(l-1))
                                                {
                                                                printf("\n\nThe given number is not a palindrome.But it can be changed in to palindrome");
                                                }
                                                else
                                                {
                                                                printf("\n\nThe given number is not a palindrome.And it cannot be changed in to palindrome");
                                                }
                                }
                }
                return 0;
}




Output:
















Thank You ...
Previous Post
Next Post
Related Posts

0 comments:

Popular Posts