0% found this document useful (0 votes)
47 views1 page

Palindrome

This C program determines if a given string is a palindrome by comparing the first and last characters, then the second and second to last, and so on. It defines a Boolean enum, writes a function called IsPalindrome that takes a string as a parameter and returns true if it is a palindrome after comparing characters from both ends inward, and a main function that gets user input, calls IsPalindrome, and prints if the string is or isn't a palindrome.

Uploaded by

vidyasagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views1 page

Palindrome

This C program determines if a given string is a palindrome by comparing the first and last characters, then the second and second to last, and so on. It defines a Boolean enum, writes a function called IsPalindrome that takes a string as a parameter and returns true if it is a palindrome after comparing characters from both ends inward, and a main function that gets user input, calls IsPalindrome, and prints if the string is or isn't a palindrome.

Uploaded by

vidyasagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

/* Write a C program to determine if the given string is a palindrome or not */

#include<stdio.h>
#include<string.h>
enum Boolean{false,true};
enum Boolean IsPalindrome(char string[])
{
int left,right,len=strlen(string);
enum Boolean matched=true;
if(len==0)
return 0;
left=0;
right=len-1;
/* Compare the first and last letter,second & second last & so on */
while(left<right&&matched)
{
if(string[left]!=string[right])
matched=false;
else
{
left++;
right--;
}
}
return matched;
}
int main()
{
char string[40];
clrscr();
printf("****Program to test if the given string is a palindrome****\n");
printf("Enter a string:");
scanf("%s",string);
if(IsPalindrome(string))
printf("The given string %s is a palindrome\n",string);
else
printf("The given string %s is not a palindrome\n",string);
getch();
return 0;
}

You might also like