Talk:Introduction to functions: Difference between revisions

From Applied Science
No edit summary
Tag: wikieditor
No edit summary
Tag: wikieditor
 
Line 1: Line 1:
I made two small mistakes that I only noticed now. The sum of the arithmetic progression requires three variables to work with any sequence, not just 1 + 2 + ... + n. The function was defined as int, which means that if the result was non integer we would lose digits.
I made two small mistakes that I only noticed now. The sum of the arithmetic progression requires three variables to work with any sequence, not just 1 + 2 + ... + n. The function was defined as int, which means that if the result was non integer we would lose digits.


In the last algorithm the sum is an integer, but it's storing the result of a division of two integers. It's losing digits at each iteration.
In the last algorithm the sum is an integer, but it's storing the result of a division of two integers. It's losing digits at each iteration. I also changed n from int to float because I think I confused the value of the variable with the value that the function returns.

Latest revision as of 23:29, 21 January 2025

I made two small mistakes that I only noticed now. The sum of the arithmetic progression requires three variables to work with any sequence, not just 1 + 2 + ... + n. The function was defined as int, which means that if the result was non integer we would lose digits.

In the last algorithm the sum is an integer, but it's storing the result of a division of two integers. It's losing digits at each iteration. I also changed n from int to float because I think I confused the value of the variable with the value that the function returns.