Computing 1x where x is positive and value printed is 0.0

I am having a problem computing 1x where x is a positive integer and getting the value in the format of 0.0 with 3 decimal digits.

Comments

  • : I am having a problem computing 1x where x is a positive integer and getting the value in the format of 0.0 with 3 decimal digits.
    :

    I'm not sure exactly what you are going for so I'm just going to quickly give you a hint on how to display 1/x where x is a positive integer.

    1/3=.333... .333... get trucated off we get 0
    10/3=3.333... .333... gets truncated off we get 3
    100/3=33.333... .333... gets truncated off we get 33

    You should be able to figure it out from there.

    If this isn't just an exercise in fixed point math or just assembly then I'd suggest using the standard C function printf instead.

    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

  • Thanks for responding. What I am looking for is this. My program that I wrote divides 1x, if I put in x=4, it gives me the value 2. What I need for it to do is multiply 1 * 10 if denominator is greater than numerator and count how many times it does this and then place that amount of decimal spaces in the output value such as count =3 then output value is 0.250, because 14 is .25.

    : : I am having a problem computing 1x where x is a positive integer and getting the value in the format of 0.0 with 3 decimal digits.
    : :
    :
    : I'm not sure exactly what you are going for so I'm just going to quickly give you a hint on how to display 1/x where x is a positive integer.
    :
    : 1/3=.333... .333... get trucated off we get 0
    : 10/3=3.333... .333... gets truncated off we get 3
    : 100/3=33.333... .333... gets truncated off we get 33
    :
    : You should be able to figure it out from there.
    :
    : If this isn't just an exercise in fixed point math or just assembly then I'd suggest using the standard C function printf instead.
    :
    : "We can't do nothing and think someone else will make it right."
    : -Kyoto Now, Bad Religion
    :
    :

  • [b][red]This message was edited by blitz at 2002-10-26 2:5:13[/red][/b][hr]
    : Thanks for responding. What I am looking for is this. My program that I wrote divides 1x, if I put in x=4, it gives me the value 2. What I need for it to do is multiply 1 * 10 if denominator is greater than numerator and count how many times it does this and then place that amount of decimal spaces in the output value such as count =3 then output value is 0.250, because 14 is .25.
    :

    Here's some C code to put you on the track:
    [code]
    void puts_1_x(int x)
    {
    const int DECIMALS = 3;
    char buff[DECIMALS + 3] = "0.";

    for (int i = 0, y = 10; i < DECIMALS; ++i) {
    div_t d = div(y, x);
    buff[i + 2] = d.quot + '0';
    y = d.rem * 10;
    }

    puts(buff);
    }
    [/code]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories