#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");
}
#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
#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;
}
#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; }
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.
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.
Is a typical home-work assignment for beginners.
/*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 (); }
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<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"); }}
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>0) { r=n % 10; sum=concat(r); n=n / 10; } print r;
sdfdg
use the strrev() function on the given string and compare with original string.If both are equal they are palindromes else not.
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.
#include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[15],b[15]; printf("Enter the string\n"); scanf("%s",&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"); }
You can do this: <?php if ( $word === strrev( $word ) ) { echo "The word is a palindrome"; } else { echo "The word is not a palindrome"; }
/*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 (); }
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
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';}
Reverse the string and compare it to the original. If they match, then it 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<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"); }}
sdfdg
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>0) { r=n % 10; sum=concat(r); n=n / 10; } print r;
A string palindrome is some words that put together form a sentence. An example is "A man, a plan, a canal - Panama".
A string palindrome is some words that put together form a sentence. An example is "A man, a plan, a canal - Panama".