C language program Which hero will take a look at my output and keep the decimal problem.

Updated on technology 2024-02-08
7 answers
  1. Anonymous users2024-02-05

    C language does not round, if you want to round it, such as a to keep two decimal places:

    float b =(int)((a * 100) +/ ;

    Output b is fine.

  2. Anonymous users2024-02-04

    The last one has to make a judgment... You don't round up five like that, you should judge that the decimal point is greater than or it's raining... Write it yourself.

  3. Anonymous users2024-02-03

    。。Formatting control issues, %1lf means one decimal place is kept

  4. Anonymous users2024-02-02

    The programming methods and ideas for using C language to make the output value a decimal are as follows:

    1.The first thing you need to do is define a variable as the number that needs to be output later. Let's take the definition of a variable a as an example. It should be noted that integer ints do not support conversion.

    2.The scanf() function is then used to accept a number entered from the keyboard, thus successfully assigning a value to variable a.

    3.Then, the printf statement is used to decimal the number a. The processing format is: [% need to keep the number of decimal places) number of formatters], here is a demonstration to keep 3 decimal places as an example: that is, %3f。

    4.Finally, click Run the program, and in the debugging window of the program, you can see that the number has been successfully converted to output with decimals.

  5. Anonymous users2024-02-01

    The above ** requires the header file include, and the setprecision function refers to setting the precision of the output, for example: float a=; cout "If the parameter in setprecision is less than the number of integer digits, it will be output exponentially.

    For example: float a=; coutfixed) and setprecision(n) together to identify the preservation of n as a decimal output. It is also important to note here that each output can only be set in order, because the scope of these two copies is for the subsequent object, not only for the latter object.

  6. Anonymous users2024-01-31

    The decimal of a language is a floating-point number.

    Floating-point numbers belong to floating binary point types, that is to say, the values of the double type will be converted into binary values such as this representation and then add and subtract, but when converted to binary ** representation, the number of digits stored in the decimal part will be insufficient, that is, infinite loop decimals.

    This results in a slight difference in the result of adding decimals.

    2.A floating-point number is a numerical representation of a number that belongs to a specific subset of rational numbers, and is used in computers to approximate any real number. Specifically, this real number is obtained by multiplying an integer or fixed-point number (i.e., mantissa number) by the integer power of a certain base (usually 2 in a computer), similar to the scientific notation of the base 10.

    3.Floating-point arithmetic refers to operations in which floating-point numbers are involved, often accompanied by approximations or rounding because they cannot be represented exactly.

    A floating-point number a is represented by two numbers m and e: a = m b e. In any such system, we choose a cardinality b (the basis of the notation system) and precision p (i.e., how many bits are used to store).

    m (i.e., mantissa number) is the p-digit of the shape (each bit is an integer between 0 and b-1 per acre, including 0 and b-1). If the first digit of m is a non-0 integer, m is called normalized. Some descriptions use a separate sign bit (s for + or -) to represent positive or negative, so that m must be positive.

    e is an exponent.

  7. Anonymous users2024-01-30

    In the programming of C, there will always be the processing of floating-point numbers, sometimes, we only need to keep 2 decimal places as the output result, at this time, the question is, how to make Cout output the specified decimal point after the number of digits?

    In C programming, we can implement it like this:

    cpp] view plain copy

    printf("%2f", sample);

    In C++, there is no formatter, and we can do this by using the setprecision() function.

    To use the setprecision() function, you must include the header file include. Here's how to use it:

    cpp] view plain copy

    cout "At this point, we will find that if the value of a is, the output result is a=, and the 0 in the second digit is omitted.

    If we want it to auto-compensate 0, we need to define the 0 before cout. ** Below:

    cpp] view plain copy

    fixed);

    cout "So we can get it. Of course, if you want to turn off the compensation of 0, you only need to cancel the fixed operation.

    cpp] view plain copy

    fixed);

    cout "Our output is back to a=.

    Reference**. cpp] view plain copy

    #include

    #include

    using namespace std;

    int main()

    float a = ;

    fixed);

    cout <:fixed);

    cout

Related questions
14 answers2024-02-08

First question: What does exit failure mean? Why do you need this thing in this program? >>>More

8 answers2024-02-08

You have to look at **", not memorize**, but you also have to learn the basics of the C language. If you don't even know ABCD, how can you read English**? Reading more about what others write is something you do after you have a certain foundation. >>>More

4 answers2024-02-08

2. 1, True 2, False (there is only one program) 3, False (not necessarily) 4, True. >>>More

7 answers2024-02-08

The first if(!) a) means that if a is equal to zero, take x -- the second and third means that if b and c are not 0, it is executed. >>>More

18 answers2024-02-08

C is process-oriented.

C++ is object-oriented. >>>More