Sunday, October 30, 2011

String palindrome program in C (without string function )

Write a Program to find whether the Given String is Palindrome or not without using
string functions.


#include<stdio.h>
#include<conio.h>
void main()
{
char s1[20];
int i,j,len=0,flag=0;
clrscr();
printf ("Enter a string:");
gets(s1);for(i=0;s1[i]!='\0';i++)
len++;
i=0;
j=len-1;
while(i<len)
{
if(s1[i]!=s1[j])
{
flag=1;
break;
}
i++;
j--;
}
if(flag==0)
printf("\nstring is palindrome ");
else
printf("\n string is not palindrome");
getch();
}


0 comments:

Post a Comment

About Me