Concept
How do you normalize a number with a while loop in C?
ComputerScienceOne / Summation
"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 in the range [1, 10). The code in Code Sample 17.5 specifically refers to the value 32145.234 but would work equally well with any non-negative value of x.\n\n1 double x = 32145.234;\n\n2 int k = 0;\n\n3 while(x > 10) {\n\n4 x = x / 10; //or: x /= 10;\n\n5 k++;\n\n6 }\n\nCode Sample 17.5.: Normalizing a Number with a While Loop in C"
Related Ideas
- What is 17?ComputerScienceOne · Normalizing a Number
- How can a while loop normalize a number by repeatedly dividing it by 10?ComputerScienceOne · Normalizing a Number
- What is a While Loop in C?ComputerScienceOne · Tax Program in C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
- How does a do-while loop work in C?ComputerScienceOne · Other Issues
- How does a do-while loop differ from a while loop in C?ComputerScienceOne · Do-While Loops
- Why should you avoid a semicolon after a while condition?ComputerScienceOne · While Loops
- Why does integer division truncate fractional results in C?ComputerScienceOne · Basic I/O
- How does C handle arithmetic operators and integer division?ComputerScienceOne · Operators