Arbitrarily enter a number to determine whether it is a palindrome number.
Methods: If the high-low position is still equal after interchange, it is a palindrome number.
#include <stdio.h>intHuiwen (unsigned intValue) {unsigned intn = value;unsigned intt =0; while(n) {t = t*Ten+ n%Ten; n = n/Ten; }return(t = = value);}intMain () {inta,tmp;printf("Please enter a number:\n");scanf("%d", &a); TMP = Huiwen (a);if(TMP) {printf("is a palindrome number. \ n "); }Else{printf("Not a palindrome number. \ n "); }return 0;}
Palindrome string judgment.
Method: Compares the string from the front backward to the forward character, if all are equal, a palindrome string.
#include <stdio.h>#include <assert.h>intHuiwen (Char*pa) {Char*left= PA; Char*right= PA; ASSERT (PA); while(*right!=' + ') {right++; }*right=' + '; while(*left==*(right-1)) {left++; right--;if(left = right-1) {return 1; } }if(*left!=*(right-1)) {return 0; }return 0;}intMain () {char a[] ="AB";intTMP = Huiwen (a);if(TMP) {printf("is a palindrome string. \ n "); }Else{printf("is not a palindrome string. \ n "); }return 0;}
The "C language" palindrome number and the return character string judgment.