Method 1
#include<stdio.h>
#include<conio.h>
int stpal(char str1[50], char str2[50]);
void main()
{
char str[50], rev[50];
int pal;
clrscr();
printf(“nnt ENTER A STRING…: “);
gets(str);
pal = stpal(str, rev);
printf(“nt THE REVERSED STRING IS…: “);
puts(rev);
if(pal)
printf(“nt THE ENTERED STRING IS A PALINDROME”);
else
printf(“nt THE ENTERED STRING IS NOT A PALINDROME”);
getch();
}
int stpal(char str1[50], char str2[50])
{
int i = 0, len = 0, r = 0, pal = 1;
while(str1[len]!=’′)
len++;
for(i=len-1; i>=0; i–)
{
str2[r] = str1[i];
r++;
}
str2[r] = ‘′;
for(i=0; i<=len-1; i++)
{
if(str1[i] == str2[i])
pal = 1;
else
{
pal = 0;
break;
}
}
return pal;
}
Method 2
#include<stdio.h>
#include<conio.h>
int stpal(char str[50]);
void main()
{
char str[50];
int pal;
clrscr();
printf(“nnt ENTER A STRING…: “);
gets(str);
pal = stpal(str);
if(pal)
printf(“nt THE ENTERED STRING IS A PALINDROME”);
else
printf(“nt THE ENTERED STRING IS NOT A PALINDROME”);
getch();
}
int stpal(char str[50])
{
int i = 0, len = 0, pal = 1;
while(str[len]!=’′)
len++;
len–;
for(i=0; i<len/2; i++)
{
if(str[i] == str[len-i])
pal = 1;
else
{
pal = 0;
break;
}
}
return pal;
}
Not Satisfied ? Just search & get the result
Related posts:
- C program – Copy the contents of one string to another string using pointer
- C program – To copy the contents of one string to another string
- C program To reverse the given string
- C program to read a string and check whether it is a palindrome or not (without using library functions). Output the given string along with suitable message.
- C program to find the length of a string without using the built-in function also check whether it is a palindrome or not
