C. Determine whether the number of hexadecimal Integers of a positive integer n is a return number.

Source: Internet
Author: User

C. Determine whether the number of hexadecimal Integers of a positive integer n is a return number.

All the methods for defining the number of input files and how to determine whether a n d-base number is a number of input files are included in my code comments, and the code is directly:

# Include <stdio. h> int circle (int n, int d);/*** @ brief main judge whether the number of return texts is in the d hexadecimal notation of positive integer n * @ return */int main (void) {/*** refers to the number of replies, that is, reading the same book as reading it backwards. For example, n = 232 indicates that the decimal book is 232. * reading and reading are both 232, it indicates n is the number of input files * There are two ways to judge whether n is in the d-base representation of n * 1: Convert n to the d-base representation first, then, the two pointers are computed simultaneously from the front to the back and from the back * To compare whether the two char values are equal. ** 2: first, the number of d-hexadecimal numbers of n is obtained, then convert the numbers from low to high to an integer to see if they are equal to n ** here we use the second method */int n; // positive integer to be judged // Save the hexadecimal number int ds [] = {2, 10, 16}; printf ("Please enter the integer N: \ n "); scanf (" % d ", & n); int I = 0; for (I = 0; I <sizeof (ds) /sizeof (ds [0]); I ++) {int isCircle = 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 the X-d hexadecimal number of a positive integer n is a return x @ param n the positive integer n * @ param d hexadecimal number *@ return 1-the number of replies, 0-not the number of input records */int circle (int n, int d) {int s = 0; int m = n; while (m) {s = s * d + m % d; m/= d;} return s = n ;}

The following is the running result of my program:

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.