c Determines whether the D-number of a positive integer n is a palindrome

Source: Internet
Author: User

All of the definitions of palindrome numbers and how to determine whether a D-number is a palindrome is in my code comments, directly on the code:

#include <stdio.h>intCircleintNintD);/** * @brief Main to determine whether the D-Binary of positive integer n is a palindrome number * @return * /intMainvoid){/** * palindrome number, is to look down and backward to see the same book, such as n=232, the decimal book is expressed as 232, * along the look and look upside down is 232, it means that n is a palindrome number * to determine whether the D-ary is a palindrome there are two ways * 1: First convert N to D     The binary representation, then the two pointers are in front and back and forward * simultaneously, compare whether two char is equal * * 2: First order the D binary number of N, and then convert the numbers from low to high to a * integer to see if n is equal * * Here we use the second way * *    intN//positive integer to be judged    //Save in binary number    intDs[] = {2,Ten, -}; printf"Please enter the integer n:\n"); scanf"%d", &n);inti =0; for(i =0; i < sizeof (DS)/sizeof (ds[0]); i++) {intIscircle = Circle (N,ds[i]);if(Iscircle = =0) {printf ("%d = <%d>: Is not circle!\n", N,ds[i]); }Else{printf ("%d = <%d>: Is circle!\n", N,ds[i]); }    }return 0;}/** * @brief Circle This function is used to determine whether a positive integer n's * d is a palindrome number * @param n is the positive integer that is judged n * @param /c4> d number * @return 1-is a palindrome number, 0-not a palindrome number */intCircleintNintD) {ints =0;intm = n; while(m)        {s = s * d + m% d;    M/= D; }returns = = n;}

Here are the results of my program's operation:

c Determines whether the D-number of a positive integer n is a palindrome

Related Article

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.