How to use the iterative C language to convert data formats

Updated on technology 2024-06-03
20 answers
  1. Anonymous users2024-02-11

    char *myitoa(int num,char *str,int radix)

    Index table*

    char index="0123456789abcdefghijklmnopqrstuvwxyz";

    unsigned unum;Intermediate variables

    int i=0,j,k;

    Determine the value of unum*

    if(radix==10&&num<0) * decimal negative *

    unum=(unsigned)-num;

    str[i++]='-';

    else unum=(unsigned)num;*Other cases*

    reverse order * do{str[i++]=index[unum%(unsigned)radix];

    unum/=radix;

    while(unum);

    str[i]='\0';

    Convert * if(str[0]=='-') k=1;Decimal Negative

    else k=0;

    char temp;

    for(j=k;j<=(i-1)/2;j++)

    temp=str[j];

    str[j] = str[i-1+k-j];

    str[i-1+k-j] = temp;

    return str;

  2. Anonymous users2024-02-10

    The most convenient thing is to cast and then output the corresponding type.

  3. Anonymous users2024-02-09

    This one is actually very simple, let's say there is a TV, I'll let you guess the price:

    You say: 4000, and I say: it's high (then you reduce the price by half and quote it once).

    You say: 2000, I say: low (then you raise the price to 4000 and 2000 in the middle).

    You say: 3000, I say: it's still low (then you raise the price to 3000 and 4000 in the middle).

    You say: 3500, I say: high (then you lower the price to 3000 and 3500 in the middle).

    You say: 3250, and I say: it's still high (then you drop the price to 3000 and 3250 in the middle).

    You say: 3125, and I say: low (then you raise the price to 3125 and 3250 in the middle).

    You say: 3200, I say: That's right!

    This is a typical iteration. When there is no expression in the calculation, you enter an initialized data (such as 4000), and then check whether it is correct through a judgment program, if it is incorrect, it is judged according to the result between the previous two times, and the final value is obtained in a gradual approximation way, which is called iteration.

    There are several conditions for this iteration: first, you have a calculation method, which is a value from the first two steps (e.g. in the previous example from the lowest high value and the highest low value from the middle value, which is a calculation).

    Second, there is a judgment program, such as the number I know in my heart, to compare your **.

    Third, there is a convergence condition (the above example is a completely correct guess, in fact, you can also allow the error to be within 100 yuan even if the guess is correct).

    I believe that if you are smart, you must understand it, otherwise you will go to Fan Wei and Zhao Benshan for answers, hahaha!

  4. Anonymous users2024-02-08

    Hey, this person is so classic, I can see it。。 Iteration is to calculate with a number one at a time, narrow down the range, and then determine what the final number is!

  5. Anonymous users2024-02-07

    x is a variable of type char, and the value range of a variable of type char is -128 127, beyond which it will take a value in a loop. For example, 128 takes the value of -128, 129 is -127, and so on. And 0xffff converted to decimal is 65535, it will go through 255 cycles, equivalent to 255, and then calculate according to the above, 255 is -1.

    Because the back is x--, the value of x is still the value of x when output, and x is subtracted by 1 after output, so the answer is c.

    You can think of it this way, as shown in the figure below, in a circle, you just start from 0 and count 65535 counterclockwise. It's going to turn 255 times back to -1, hehe.

  6. Anonymous users2024-02-06

    This ** is trying to assign 0xffff to x, but the char variable only occupies one byte, so the value of x is only 0xff, and then you output it as an integer, without specifying a symbol, so the compiler outputs it as the default signed number. printf("%d ", x--) is to output x and then subtract 1, 0xff is -1, so the output is -1

  7. Anonymous users2024-02-05

    First of all, 0xffff is a hexadecimal, calculate its value, 16 4-1 = 65535 = 32767*2+1, what is the concept of 32767? i.e. the maximum value of an int type (signed), 65535 is already overflowing.

  8. Anonymous users2024-02-04

    You need to pay attention to the "%d" in printf. It's yours"x"are different decimal systems, and the decimal systems are convertible to each other. You don't have to know how to convert, it's calculated by the system. We don't need to count.

  9. Anonymous users2024-02-03

    This, you are like this, yours can only be converted to binary, not to octal or hexadecimal; In 8 and 16 decimal systems.

    There are characters such as a, b, and so on, and your answer will naturally be problematic.

    Such as when converting to hexadecimal.

    After n%t>9 it will be converted to capital letters;

    The idea of your program is to use the idea of the stack to press the remainder numbers into the stack in turn; And then pop it all up when the stack isn't empty??

  10. Anonymous users2024-02-02

    The iterative method is to make the solution of the equation constantly close to the real solution. This is a numerical calculation method. The idea is to follow the above steps, only set two x0, x1 starts x0 represents the first value, x1 represents the second value after the first iteration, let x0 = x1, x1 = new value, so that x0 represents the second value, x1 represents the third value and so on...

    until the error meets the requirements.

  11. Anonymous users2024-02-01

    The iterative method is a process of continuously using the old value of a variable to recursively extrapolate the new value. The fun function sets the loop when the absolute value of x0-x1 is less than the end of the loop. #include

    #include

    floatfun()

    floatx,n=,root;

    while(root>=<=

    x=n;n=cos(x);

    root=x-n;} root=n; returnrootvoid

    main()

    floatf=fun();

    printf("root=%f",f);

  12. Anonymous users2024-01-31

    You can't do it, but you can't compile it?

    Or is it the result on the run error?

    Syntactically, both of the above procedures are correct, except that the former executes the loop body first, and then determines the loop condition. If you are typing and the result of the loop does not hold from the start, then the results of the two programs must be different.

    Another point is caused by differences in compilation systems.

  13. Anonymous users2024-01-30

    do-while will run at least once, while while will jump out of the loop if it is not eligible.

  14. Anonymous users2024-01-29

    I run under vc without error, if I pick the error, I feel that c is not initialized.

  15. Anonymous users2024-01-28

    When the second while(fabs(c) x>1e-5) is executed, it is impossible to determine whether the conditional statement is true or false, so C must be assigned a value first.

  16. Anonymous users2024-01-27

    x is an int first, then y = 1 2 (with a value of 0), and then 0 is converted to a double type. Then convert y(double type) to lf type.

  17. Anonymous users2024-01-26

    Forcibly converts 1 x to double in just one place

    double y = double)1/x;

  18. Anonymous users2024-01-25

    Convert 1 x to double and give y

  19. Anonymous users2024-01-24

    #include

    #include

    int factorial(int n)

    int main ()

    It's a quest n!The program, with the iteration, should be able to understand!!

  20. Anonymous users2024-01-23

    *Iteration is that the function calls itself, just pay attention to selecting the end condition of the iteration when using it, and don't fall into infinite iteration. An example of a simple function for recursively factoring is given below.

    long jiechen(long n)

Related questions
8 answers2024-06-03

Isn't it over if you do a division of seconds?

15 answers2024-06-03

In the standard output of the C++ language, there are hexadecimal, decimal, and octal output formats, but there is no binary output format. So if you want to output binary, you can only write your own functions for output. >>>More

7 answers2024-06-03

1) In the Poisson distribution, when finding the value of x, when p(x=k) is the maximum, set it to pxmax >>>More

7 answers2024-06-03

It's called the [batch] program, in fact, don't think that the program you mentioned above to deal with garbage is really powerful, it's amazing, when you have learned DOS, that program can be said to be a very simple thing; >>>More