The judgment of a palindrome (number, string)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.