Sunday, May 5, 2013

Write a C program to determine if the given String is Palindrome or not


/*Write a C program to determine if the given String is Palindrome or not*/

#include<stdio.h>
#include<conio.h>
#include<string.h>

int is_palindrome(char[]);

main()
{
    char ch[50];
    int t;
    clrscr();
    printf("Enter String:");
    scanf("%s",ch);
    t=is_palindrome(ch);
    if(t==1)
    printf("Given is palindrome");
    else
    printf("Given is not palindrome");
    getch();
}

int is_palindrome(char s1[])
{
    char s2[50];
    int l,i;
    l=strlen(s1);
    for(i=0;i<l;i++)
    s2[l-(i+1)]=s1[i];
    for(i=0;i<l;i++)
    if(s1[i]!=s2[i])
        return 0;
    else
        return 1;
}


output:

Enter String:  liril
Given is palindrome

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More