Wednesday, July 20, 2011

Program to find the length, reverse of a string and to check it is palindrome or not

/*Serial No.52     [swami24.cpp]*/

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,length=0,flag;
char str[10],rev[10];
clrscr();
printf("Enter the string==>");
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
{
length++;
}
printf("\nLength of %s is ==>%d\n",str,length);
length--;
for(i=0;length>=0;i++)
{
 rev[i]=str[length];
 length--;
}
rev[i]='\0';
printf("\nReverse of %s is ==>%s\n",str,rev);

 length++;
for(i=0;rev[i]!='\0';i++)
{
length++;
}
printf("\nLength of %s is ==>%d\n",rev,length);

for(i=0;str[i]!='\0'||rev[i]!='\0';i++)
{
if(str[i]!=rev[i])
    {
    flag=1;
    break;
    }
}
if(flag==1)
printf("\nString is not polyndrom");
else
printf("\nString is polyndrom");
getch();
}

No comments:

Post a Comment

If you have any doubt, feel free to ask...