answersLogoWhite

0

Program to find palindrome in a string?

Updated: 8/10/2023
User Avatar

Koderthephoder

Lvl 1
13y ago

Best Answer

#include
#include
void main()
{
char str1[80];
int i,j,flag=1;

printf("enter a word:");
gets(str1);
for(i=0,j= (strlen(str1)-1);i<=(strlen(str1)-1),j>=0;i++,j--)
{
if(str1[i]!=str1[j])
flag=0;
}
if(flag)
printf("palindrome");
else
printf("not a palindrome");
}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

#include<iostream.h>

#include<stdio.h>

#include<string.h>

#include<process.h>

void main()

{

char str[50];

int i,l,f;

cout<<"\n\tProgram to check given string is palindrome or not";

cout<<"\n\tEnter a string:";

gets(str);

l=strlen(str);

for(i=0;i<l/2;i++)

{

if(str[i]!=str[l-i-1])

{

cout<<"\n\tNot palindrome";

exit(0);

}

}

cout<<"\n\tPalindrome";

}

//By Gem George

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

#include

unsigned reverse (unsigned num) {
unsigned dgt, acc = 0;
while (num>0) { dgt = num%10; // determine last digit of num (remainder after division by 10)
rev = rev * 10; // left-shift the accumulator by 1 decimal digit
rev = rev + dgt; // add the digit
num = num / 10; // right-shift the number by 1 decimal digit
}
return acc; // the accumulator is the reverse of original number
}

bool is_palindrome (unsigned num) {
return num == reverse (num);
}

int main (void) {
unsigned num;
printf ("Enter a number greater than zero: ");
scanf ("%u\n", &num);
if (is_palindrome (num))
printf ("The number is a palindrome\n");
else
printf ("The number is not a palindrome\n"); return 0;
}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago
C Answer#include

#include

#include

int max=0;

int copy(char *str,int n)

{

char *st;

int i;

st=malloc(sizeof(char)*n);

for(i=0;i<=n;i++)

{

st[i]=str[i];

}

st[n+1]='\0';

printf("Palindrome is %s\n",st);

}

int rev(char *s)

{

int j,k,r,len;

len=strlen(s);

for(j=len-1;j>0;j--)

{

k=0;

r=j;

while(k < r && s[k] == s[r])

{

k++;

r--;

}

if(k >= r)

{

//printf("Palindrome Found\n");

if((j+1) > max)

{

max=j+1;

}

copy(s,j);

}

}

}

int palind(char *s)

{

int i,len;

len=strlen(s);

for(i=0;i

{

rev(&s[i]);

}

}

int main()

{

char Sentence[50];

printf("Enter the Sentence\n");

gets(Sentence);

palind(Sentence);

printf("The maximum length is %d",max);

getchar();

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Parse each of the words by detecting spaces (that is, extract one word at a time); use a function to revert the string (most languages have such a function); compare whether the reverted word is equal to the original word.

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

Remove all spaces and punctuation from the string. Convert the string to lower case. Now copy the string. You now have two strings, a and b. Reverse string b. If a equals b, the string is a palindrome.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Is a typical home-work assignment for beginners.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Program to find palindrome in a string?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Program to check that given string is palindrome or not in C?

/*To check whether a string is palindrome*/includeincludevoid main () { int i,j,f=0; char a[10]; clrscr (); gets(a); for (i=0;a[i]!='\0';i++) { } i--; for (j=0;a[j]!='\0';j++,i--) { if (a[i]!=a[j]) f=1; } if (f==0) printf("string is palindrome"); else printf("string is not palindrome"); getch (); }


Bluej program-read a string and check if the given string is a palindrome?

import java.util.Scanner; public class Palindrome{ public static void main(String[] args){ String front; String back =""; char[] failure; String backwards; Scanner input=new Scanner(System.in); System.out.print("Enter a word: "); front=input.next(); front=front.replaceAll(" ", ""); failure=front.toCharArray(); for (int i=0; i&lt;failure.length; i++){ back=failure[i] + back; } if (front.equals(back)){ System.out.print("That word is a palindrome"); }else System.out.print("That word is not a palindrome"); }}


Write c program to print palindrome using string without using strrev strlen strcam?

sdfdg


Write a program using method plainto check whether a string is a palindrome or not A palindrome is a string that reads the same from left to right and vice-versa?

Palindrome number is a number like 121 which remains the same when its digits are reversed. To find this number in a simple java program, just follow the below way. sum = 0; while(n&gt;0) { r=n % 10; sum=concat(r); n=n / 10; } print r;


Wap in c plus plus to find out the string is palindrome or not in?

use the strrev() function on the given string and compare with original string.If both are equal they are palindromes else not.

Related questions

What are examples of a palindrome program forward and backwards?

To check if a string is a palindrome, point to each end of the string and work inwards towards the middle. If the characters pointed at differ, the string is not a palindrome. When the pointers meet or cross each other, the string is a palindrome. Note that the string cannot contain whitespace or punctuation and comparisons must not be case-sensitive.


Program to find palindrome using C programming?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; #include&lt;string.h&gt; void main() { char a[15],b[15]; printf("Enter the string\n"); scanf("%s",&amp;a); strcpy(b,a); strrev(a); if(strcmp(a,b)==0) printf("The String is a palindrome"); else printf("The String is not a palindrome"); }


Write a PHP program to check whether the string is palindrome or not?

You can do this: &lt;?php if ( $word === strrev( $word ) ) { echo "The word is a palindrome"; } else { echo "The word is not a palindrome"; }


Program to check that given string is palindrome or not in C?

/*To check whether a string is palindrome*/includeincludevoid main () { int i,j,f=0; char a[10]; clrscr (); gets(a); for (i=0;a[i]!='\0';i++) { } i--; for (j=0;a[j]!='\0';j++,i--) { if (a[i]!=a[j]) f=1; } if (f==0) printf("string is palindrome"); else printf("string is not palindrome"); getch (); }


How do you write a program in C to check whether a word is a palindrome or not?

It is a simple program. i think u may understand it :#include#include#includevoid main(){char s[10]=answers.com;char x[10];int a;clrscr();strcpy(x,s);strrev(s);a=strcmp(s,x);if(a==0){printf("the entered string is palindrome");}else{printf("the entered string is not palindrome");}output:given string is not palindrome


Program for palindrome in php?

You could use a function like this:function isPalindrome($string) {$string = strtolower($string);return (strrev($string) == $string) ? true : false;}and then to check a palindrome call an if statement like so:if(isPalindrome($test)) {echo $test.' is a palindrome';}else {echo $test.' is not a palindrome';}


How do you determine if a given string is palindrome or not?

Reverse the string and compare it to the original. If they match, then it is a palindrome.


Bluej program-read a string and check if the given string is a palindrome?

import java.util.Scanner; public class Palindrome{ public static void main(String[] args){ String front; String back =""; char[] failure; String backwards; Scanner input=new Scanner(System.in); System.out.print("Enter a word: "); front=input.next(); front=front.replaceAll(" ", ""); failure=front.toCharArray(); for (int i=0; i&lt;failure.length; i++){ back=failure[i] + back; } if (front.equals(back)){ System.out.print("That word is a palindrome"); }else System.out.print("That word is not a palindrome"); }}


Write c program to print palindrome using string without using strrev strlen strcam?

sdfdg


Write a program using method plainto check whether a string is a palindrome or not A palindrome is a string that reads the same from left to right and vice-versa?

Palindrome number is a number like 121 which remains the same when its digits are reversed. To find this number in a simple java program, just follow the below way. sum = 0; while(n&gt;0) { r=n % 10; sum=concat(r); n=n / 10; } print r;


What is string palindrome?

A string palindrome is some words that put together form a sentence. An example is "A man, a plan, a canal - Panama".


What is a string palindrome?

A string palindrome is some words that put together form a sentence. An example is "A man, a plan, a canal - Panama".