Tuesday, 10 January 2012

String Palindrome Not using String Function

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

void main()
{
    char text[100];
    int begin,middle,end,length=0;
    clrscr();
    printf("Enter the string::\n");
    gets(text);
    while(text[length]!='\0')
    length++;
    end=length-1;
    middle=length/2;
    for(begin=0;begin<middle;begin++)
    {
        if(text[begin]!=text[end])
        {
            printf("Not a palindrome.\n");
            break;
        }
        end--;
    }
    if(begin==middle)
    printf("Palindrome.\n");
    getch();
}

No comments:

Post a Comment