Program:
#include<stdio.h>
#include<string.h>
//#include<conio.h>
int ispalindrome(char str[20])
{
int left,right,flag;
if(strlen(str)==0)
return 1;
else
{
left=0;
right=strlen(str)-1;
flag=1;
while(left<right && flag)
{
if (str[left]!= str[right])
flag=0;
else
{
left++;
right--;
}
}
return flag;
}
}
void main()
{
char str[200];
printf("Enter the string: ");
scanf("%s",str);
if(ispalindrome(str))
printf("String is palindrome.\n");
else
printf("String is not palindrome.\n");
// getch();
}
Output:
nn@linuxmint ~ $ gcc c10.c
nn@linuxmint ~ $ ./a.out
Enter the string: malayalam
String is palindrome.
nn@linuxmint ~ $
#include<stdio.h>
#include<string.h>
//#include<conio.h>
int ispalindrome(char str[20])
{
int left,right,flag;
if(strlen(str)==0)
return 1;
else
{
left=0;
right=strlen(str)-1;
flag=1;
while(left<right && flag)
{
if (str[left]!= str[right])
flag=0;
else
{
left++;
right--;
}
}
return flag;
}
}
void main()
{
char str[200];
printf("Enter the string: ");
scanf("%s",str);
if(ispalindrome(str))
printf("String is palindrome.\n");
else
printf("String is not palindrome.\n");
// getch();
}
Output:
nn@linuxmint ~ $ gcc c10.c
nn@linuxmint ~ $ ./a.out
Enter the string: malayalam
String is palindrome.
nn@linuxmint ~ $
0 comments:
Post a Comment