1, palindrome number
#include <stdio.h>int length (int n) {int count=0;while (n) {n/=10;count++;} return count;} int Num_huiwen (int n) {int i=0;int arr[20];if (n<=0) {printf ("Reenter number:"), scanf ("%d", &n); Huiwen (n);} Else{int len=length (n); for (i=0;i<len;i++) {arr[i]=n%10;n/=10;} for (i=len-1;i>=0;i--) {if (Arr[i]==arr[len-i-1]) {return 1;} Else{return 0;}}}} int main () {int num=0;int ret=0;printf ("Enter Number:"), scanf ("%d", &num), Ret=num_huiwen (num), if (ret==1) {printf (" This number is a palindrome number! \ n ");} else{printf ("The number is not a palindrome number!") \ n ");} return 0;}
2. Back text character
#include <stdio.h> #include <string.h>int char_huiwen (char arr[]) {int Len=strlen (arr); int i=0;for (i=0;i <len;i++) {if (Arr[i]==arr[len-i-1]) {return 1;} Else{return 0;}}} int main () {char arr[20]= "Hello Olleh"; int Ret=char_huiwen (arr); if (ret==1) {printf ("The string is a palindrome string!) \ n ");} Else{printf ("The string is not a palindrome string!") \ n ");} return 0;}
This article is from the "Flower Open Shore" blog, please be sure to keep this source http://zxtong.blog.51cto.com/10697148/1707251
The judgment of a palindrome (number, string)