Concept
What is 17?
ComputerScienceOne / Normalizing a Number
"17.5. Examples 17.5. Examples 17.5.1. Normalizing a Number 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 . 1 double x = 32145.234; 2 int k = 0; 3 while(x > 10) { 4 x = x / 10; //or: x /= 10; 5 k++; 6 } Code Sample 17.5.: Normalizing a Number with a While Loop in C 17.5.2. Summation Let’s revisit the example from Section 4.2.1 in which we computed the sum of integers 1 + 2 + · · · + 10. The code is presented in Code Sample 17.6 1 int i; 2 int sum = 0; 3 for(i=1; i<=10; i++) { 4 sum += i; 5 } Code Sample 17.6.: Summation of Numbers using a For Loop in C Of course we could easily have generalized the code somewhat. Instead of computing a sum up to a particular number, we could have written it to sum up to another variable n , in which case the for loop would instead look like the following. 287"
Related Ideas
- How do you normalize a number with a while loop in C?ComputerScienceOne · Summation
- How do you compute a summation with a for loop in C?ComputerScienceOne · Summation
- How can a while loop normalize a number by repeatedly dividing it by 10?ComputerScienceOne · Normalizing a Number
- How can a Java for loop be generalized to sum integers up to another variable?ComputerScienceOne · Normalizing a Number
- What topic is covered in section 17.5.2?ComputerScienceOne · Normalizing a Number . . . . . . . . . . . . . . . . . . . . . . . .
- What is 285 17?ComputerScienceOne · For Loop in C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
- How can a for loop calculate the sum of numbers from 1 to 10?ComputerScienceOne · Nested Loops
- How can a summation loop be generalized to sum up to a variable n?ComputerScienceOne · Summation