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
- How can a while loop normalize a number by repeatedly dividing it by 10?ComputerScienceOne · Normalizing a Number
- How does an enhanced for loop compute the sum of a list of integers?ComputerScienceOne · Summation
- How can a summation loop be generalized to sum up to a variable n?ComputerScienceOne · Summation
- How can a Java for loop be generalized to sum integers up to another variable?ComputerScienceOne · Normalizing a Number
- How can a for loop compute a generalized summation in PHP?ComputerScienceOne · Summation