Bifalgorithm post · Computer science one · Normalizing a Number

How can a while loop normalize a number by repeatedly dividing it by 10?

How can a while loop normalize a number by repeatedly dividing it by 10? (Computer science one · Normalizing a Number) — "Let’s revisit the example from Sectio…

Ideas in this flowchart

  • Normalizing a number with a while loop in Java
  • The algorithm repeatedly divides a number by 10 to normalize it.
  • The loop continues while x is greater than 10.
  • Each iteration replaces x with x / 10, equivalently written as x /= 10.
  • Each iteration increments the counter k.
  • The process stops when x is no longer greater than 10.
  • The example initializes x with the value 32145.234.
  • The same code works with any value of x.
  • The counter k is initialized to 0 before the loop begins.
Feed/

How can a while loop normalize a number by repeatedly dividing it by 10?

No cover

Channel

Computer science one

1 page

"Let’s revisit the example from Section 4.1.1 in which we normalize a number by continually dividing it by 10 until it is less than 10. The code in Code Sample 28.7 specifically refers to the value 32145.234 but would work equally well with any value of x.\n\ndouble x = 32145.234;\n\nint k = 0;\n\nwhile(x > 10) {\n\nx = x / 10; //or: x /= 10;\n\nk++;\n\n}\n\nCode Sample 28.7.: Normalizing a Number with a While Loop in Java"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.