Pages

Subscribe:

Palindrome Program In C

Palindrome is a word , number that can  be read same front direction and opposite direction.


Example :


  • Palindrome  words (Strings ) 
  1. Racecar
  2. Madam
  3. Level
  4. Radar
  5. Toot
  6. Pop
  • Palindrome numbers
  1. 121
  2. 1221
  3. 141
  4. 1234321
  5. 676
1.To Check whether Given String Is Palindrome or Not  :


Program :
#include<stdio.h>
#include<conio.h>
int pali( char []);
void main()
{
    char ch;
    do{
        int n;
        char s[20];
        clrscr();
        printf("\n Enter the string:");
        gets(s);
        n=pali(s);

        if(n==1)

            printf("\n <%s> is palindrome \n",s);
        else

            printf("\n <%s> not palindrome \n",s);
    printf("Continue(y/n):");
    ch=getch();
    }while(ch=='y'||ch=='Y');
}
int pali(char s[])
{
    int r,n=1,l=0;
    char toupper(char);

       for(r=0;s[r]!='\0';r++);

       r=r-1;
       while(l<r)
       {
        if(toupper (s[l])!=toupper(s[r]))
        {
            n=0;
            break;
        }
           l++;
           r--;

       }
       return n;

}
char toupper(char c)
{
    if(c>='a' &&  c<='z')
    c=c-32;
    return c;
}


Note : Madam ,First letter  M is a Capital and Last letter  m is a small letter . There ASCII value  is deference  M = 77 and m= 109 . Toupper function works that small m letter convert to capital M letter 109-32=77.


Output :


No Preview




2.To Check whether Given Number Is Palindrome or Not  :


Program :


#include<stdio.h>
#include<conio.h>
void main()
{

int a,b,c=0,r=0;


    clrscr();
    printf("\t Enter any no :");
    scanf("%d",&a);
    b=a;
while(a>0)
{
r=a%10;
c=c*10+r;
a=a/10;
}
    if(c==b)
        printf("\t <%d> the no is palindrome",b);
    else
        printf("\t <%d> is not palindrome",b);
        
getch();

}




Output :







If you have any Further Information and Quires about this Article don't hesitate to comment in comment box below.
                                                           AND

 If you like this article , like our Facebook like page and click  +1 to support 123techguide
comments powered by Disqus
 

Listed In

Bloggers - Meet Millions of Bloggers http://Link-exchange.comxa.com
Blog Search: The Source for Blogs Internet Blogs

Disclaimer

The contents in this blog are taken from various sources available over the internet, therefore we do not gurantee of it's accuracy, if you find any of the content in the blog is infringing it's copyright, please do email us on '123techguide@gmail.com' and we will make sure to remove the same from the blog at the earliest.