(12C) Sum and Average - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (12C) Sum and Average (/thread-11614.html) |
(12C) Sum and Average - Gamo - 10-20-2018 07:28 AM Program to find given first n natural number's sum and average. Procedure: Answer start with Average [X<>Y] then Sum n [R/S] average [X<>Y] sum Example: FIX 2 -------------------------------------- Find Sum and Average of 7 7 [R/S] 4 [X<>Y] 28 Answer: Average is 4 Sum is 28 -------------------------------------- Find Sum and Average of 100 100 [R/S] 50.50 [X<>Y] 5050 Answer: Average is 50.50 Sum is 5050 Program: Sum and Average Code:
Gamo RE: (12C) Sum and Average - Dieter - 10-20-2018 09:52 AM (10-20-2018 07:28 AM)Gamo Wrote: Program to find given first n natural number's sum and average. Nice use of the stack. But it can be done shorter: sum = n(n+1)/2 average = sum/n = (n+1)/2 Code: 01 ENTER Dieter RE: (12C) Sum and Average - Gamo - 10-21-2018 03:19 AM Thanks Dieter You version is more refine. Gamo |