#include <stdio.h>
#include <string.h>
#define N 100
#define PALINDROME 0
#define NONPALINDROME 1
/*Program that tells you whether what you enter is a palindrome or not*/
char pal[N]; //input line
int i; //counter
int k; //counter
int tag;
int flag = PALINDROME; /*flag=0 ->palindrome, flag =1 ->nonpalindrome*/
int main()
{
printf("Enter something: \n");
scanf("%s", pal);
tag = strlen(pal); /*determine length of string*/
/* pointer running from the beginning and the end simultaneously
looking for two characters that don't match */
/* initially assumed that string IS a palindrome */
/* the following for loop looks for inequality and flags the string as
a non palindrome the moment two characters don't match */
for (i=0,k=tag-1; i=0; i++,k--) {
if(pal[i] != pal[k]) {
flag=NONPALINDROME;
break;
}
}
if(flag == PALINDROME) {
printf("This is a palindrome\n");
}
else {
printf("This is NOT a palindrome\n");
}
return 0;
}
#include <stdio.h>
#include <string.h>
#define N 100
#define PALINDROME 0
#define NONPALINDROME 1
/*Program that tells you whether what you enter is a palindrome or not*/
char pal[N]; //input line
int i; //counter
int k; //counter
int tag;
int flag = PALINDROME; /*flag=0 ->palindrome, flag =1 ->nonpalindrome*/
int main()
{
printf("Enter something: \n");
scanf("%s", pal);
tag = strlen(pal); /*determine length of string*/
/* pointer running from the beginning and the end simultaneously
looking for two characters that don't match */
/* initially assumed that string IS a palindrome */
/* the following for loop looks for inequality and flags the string as
a non palindrome the moment two characters don't match */
for (i=0,k=tag-1; i=0; i++,k--) {
if(pal[i] != pal[k]) {
flag=NONPALINDROME;
break;
}
}
if(flag == PALINDROME) {
printf("This is a palindrome\n");
}
else {
printf("This is NOT a palindrome\n");
}
return 0;
}
Program:
#include
#include
void main()
{
long int n,m,rev=0,r;
clrscr();
printf("\nEnter the number:");
scanf("%ld",&n);
m=n;
while(n>0)
{
r=n%10;
rev=rev*10+r;
n=n/10;
}
if(rev==m)
printf("Palindrome");
else
printf("Not Palindrome");
getch();
}
output:
Enter the number:123321
Palindrome
Enter the number:12420
Not 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 (); }
#include <stdio.h> #include<conio.h> void main () { int a,r,n,sum=0; clrscr(); printf("enter the number"); scanf("%d",& n); c=n while (n!=0) { a=n%10; n=n/10; sum=sum*a+a } printf("the reverse is %d \n",sum); if(c==sum) printf("\n the given number is palindrome"); else printf("\n the given number is not a palindrome"); getch(); }
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;
class test { public static void main(int num) { int num2=num; int rnum=0; while (num2>0) { int q=num2/10; int dig=num2%10; rnum = rnum*10+dig; num2=q; } if (rnum==num) System.out.println("Palindrome number"); else System.out.println("Not a Palindrome number"); } }
This program only suits PHP. If you want a proper one try C program for it available on web <body> <?php if(isset($_POST['submit'])) { $text = $_POST['text']; $string = mysql_real_escape_string($text); $invert = strrev($string); if($string == $invert) { echo "<br>Given number is a palindrome!!"; } else { echo "<br>Given number is not a palindrome!!"; } } ?> <form method="post"> <input type="text" name="text" id="text" /> <input type="submit" name="submit" value="Submit" id="submit" onclick="<?php $_SERVER['PHP_SELF']; ?>" /> </form> </body>
You can do this: <?php if ( $word === strrev( $word ) ) { echo "The word is a palindrome"; } else { echo "The word is not a palindrome"; }
If you want to check whether a string is a palindrome, you can reverse the string (for example, the Java class StringBuffer has a reverse() method), and then compare whether the two strings - the original string and the reverted string - are equal. Alternately, you could write a loop that checks whether the first character of the string is equal to the last one, the second is equal to the second-last one, etc.; that is, you have a counter variable (in a "for" loop) that goes from zero to length - 1 (call it "i"), and compare character #i with character #(length-i-1) inside the loop.
unsigned reverse (unsigned n) { unsigned r = 0; while (n) { r *= 10; r += (n%10); n /= 10; } return r; } bool is_palindrome (unsigned n) { return n == reverse (n); } int main () { unsigned num; printf ("Enter a number: "); scanf ("%d", num); if (is_palindrome (num)) printf ("%d is a palindrome\n"); else printf ("%d is not a palindrome\n"); return 0; }
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
/*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 (); }
#include <math.h> // this will test if a base 10 integer is a palindrome int is_palindrome_10(const unsigned int n) { if( n < 10 ) return 1; unsigned int i, num_digits, num_digits_2; num_digits = ((unsigned int) log10(n) + 1); num_digits_2 = num_digits/2; // sorry the if statement is so ugly. looks neater in my editor :\ for(i = 0; i < num_digits_2; ++i) if( ((unsigned int) ( n/pow(10, num_digits - i - 1) ) % 10) != ((unsigned int) ( n/pow(10, i) ) % 10) ) return 0; return 1; }
#include <stdio.h> #include<conio.h> void main () { int a,r,n,sum=0; clrscr(); printf("enter the number"); scanf("%d",& n); c=n while (n!=0) { a=n%10; n=n/10; sum=sum*a+a } printf("the reverse is %d \n",sum); if(c==sum) printf("\n the given number is palindrome"); else printf("\n the given number is not a palindrome"); getch(); }
45654 is the palindrome because it reads the same whether forward or backward.
The number '4' can be considered a palindrome because it is read the same whether forward or backward. It can become another palindrome when it is considered as 2x2.
Because palindrome is not a palindrome. However, a dromedary is the same thing whether it is going backwards or forwards.
A palindrome indicates a statement that has the same meaning, whether read backward or forward.
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;