The C language 20 line code asks for all isomorphic numbers less than or equal to 10000.

Source: Internet
Author: User
Tags pow

problem: The number of square-low lows is exactly equal to the number of isomorphism numbers. Ask for all isomorphism numbers less than 10000.

compilation environment: vc6.0

#include <stdio.h> #include <math.h>                     &NBSP ;
             //Call POW () function. void Main () {    int n,i,m,k;                       &NBS P            //definition: N for digits, I for loop number,                                                     &NB
Sp;//m and k are the squares of I (the two uses are different, K can be replaced by i*i).     for (i = 1;i <= 10000;i++) {                     / Cycle
(range for 1~10000, modifiable)         k = i * i;         n = 1;                                   &NB Sp
 //When the square is less than 1 o'clock, the number of digits is 1.         m = k;   &nbsp                                   &NB Sp             while (M >=) {n++;m/=}            
 //the number of digits of the square number.         if (n% 2 = 0) {                      & nbsp
     //when the number of digits in the square number is even.                                   &NB Sp
                 //Note: Here curly braces are not available, otherwise the second if will be aligned with else.             if (i = = k (int) pow (N/2))        //determine if I equals squared number to Low
The remainder of the number of bits obtained.                 printf ("%d\n", I);}                  /Output I, if you want to in the output of the square, then add K.           else{  &NBsp                                   &NB sp;//when the number of digits in the square number is odd.
Note: Here curly braces are available.             if (i = = k (int) Pow ((n + 1)/2))           &NBSP ;
    printf ("%d\n", I);}    } system ("Pause");                              //vc6.0 need to add On system ("Pause"); }

About this line of code:

  if (i = = k (int) pow (N/2))

1, K can be replaced with i*i.

2, the remainder symbol% can not be used for floating-point numbers, only for integers.

3, POW () function in the vc6.0 prototype is double pow (double x, double y); The return value is of type double , so it needs to be converted to an int type.

4, the meaning of the code is to first calculate the square number of i*i lower digits (that is, the square up to the half, divided into high and low number of two parts, such as the number of 964852 low number of 852, the number of digits is 3,; number 26547 /c7> Low number is 547 , the number of digits is 3), and then the number of squares to 10 of the lower digits of the power of the remainder (for example, when K is 3264 , after the remainder for the, low position A power of several times is 2), and finally compared with I.

The result of the code operation is:



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.