For example, from 0 to 60. Obviously I know how many numbers exist, but what I do is know how to make my algorithm find out this mathematically.
For example, from 0 to 60. Obviously I know how many numbers exist, but what I do is know how to make my algorithm find out this mathematically.
function quantosNumerosExistem(x, y) {
return Math.abs(y - x) + 1;
}
document.write(
" De 3 até 10: " + quantosNumerosExistem(3, 10) + "<br>" +
" De 0 até 60: " + quantosNumerosExistem(0, 60) + "<br>" +
" De -2 até 2: " + quantosNumerosExistem(-2, 2) + "<br>" +
" De 0 até 0: " + quantosNumerosExistem(0, 0) + "<br>" +
" De 0 até 1: " + quantosNumerosExistem(0, 1) + "<br>" +
" De -10 até -8: " + quantosNumerosExistem(-10, -8)
);