Bifalgorithm post · Computer science one · Normalizing a Number

What is 17?

What is 17? (Computer science one · Normalizing a Number) — "17.5. Examples 17.5. Examples 17.5.1. Normalizing a Number Let’s revisit the example from Section…

Ideas in this flowchart

  • Ejemplos de bucles en C
  • Normalización de un número mediante un bucle while
  • El valor inicial de x es 32145.234, aunque el código funciona con cualquier valor no negativo.
  • El bucle continúa mientras x sea mayor que 10.
  • En cada iteración, x se divide entre 10.
  • La variable k cuenta las divisiones realizadas.
  • El proceso normaliza x hasta situarlo en el rango [1, 10).
  • Sumación de números mediante un bucle for
  • La variable sum comienza con el valor 0.
  • El bucle recorre los valores de i desde 1 hasta 10.
  • En cada iteración, i se añade a sum.
  • El código puede generalizarse para sumar hasta otra variable n.
Feed/

What is 17?

No cover

Channel

Computer science one

1 page

"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"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.