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

What is 17? | ComputerScienceOne | Bifalgorithm | Bifalgorithm