The algorithm of palindrome number in C language

Source: Internet
Author: User

"Palindrome" is a sentence to read and read through. It is a rhetorical way and word games, such as "I for everyone, everyone for me" and so on. In mathematics there are also such a number of numbers that have this characteristic and become palindrome numbers (palindrome number).

set N is a random natural number. If the numbers of n are reversed and the natural number N1 is equal to N, then N is a palindrome number. For example, if n=1234321, then n is a palindrome number. But if n=1234567, then n is not a palindrome number.

On the code:

#include <stdio.h> #define  true  1 #define  false 0 int Huiwenshu (int n) {int p;p=n;  int k=0;//The n in reverse and saves it in the K variable while (p!=0) {K=K*10+P%10;P=P/10;} Infer the result after the reverse of the K and the original input number n is equal, equal return Trueif (k==n) return True;elsereturn false;} int  main (void) {printf ("Please input number:\n"); static int num; static int ret; SCANF ("%d", &num); ret = Huiwensh U (num), if (1 = = ret) printf ("Palindrome number \ n"), elseprintf ("not palindrome \ n"); return 0;}
Execution Result:



Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">

The algorithm of palindrome number in C language

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.