The "C language" palindrome number and the return character string judgment.

Source: Internet
Author: User

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.

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.