(12C) Sum and Average
10-20-2018, 07:28 AM (This post was last modified: 10-20-2018 07:29 AM by Gamo.)
Post: #1
 Gamo Senior Member Posts: 499 Joined: Dec 2016
(12C) Sum and Average
Program to find given first n natural number's sum and average.

Procedure:

n [R/S] average [X<>Y] sum

Example: FIX 2

--------------------------------------

Find Sum and Average of 7

7 [R/S] 4 [X<>Y] 28

Average is 4
Sum is 28

--------------------------------------

Find Sum and Average of 100

100 [R/S] 50.50 [X<>Y] 5050

Average is 50.50
Sum is 5050

Program: Sum and Average
Code:

01 ENTER
02 ENTER
03 ENTER
04  1
05  +
06  x
07  2
08  ÷
09 ENTER
10 Rv
11 X<>Y
12  ÷
13 X<>Y
14 Rv
15 GTO 00

Gamo
10-20-2018, 09:52 AM
Post: #2
 Dieter Senior Member Posts: 2,398 Joined: Dec 2013
RE: (12C) Sum and Average
(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
02 ENTER
04  1
05  +
06  2
07  ÷
08  x
08 LstX
09 GTO 00

Dieter
10-21-2018, 03:19 AM
Post: #3
 Gamo Senior Member Posts: 499 Joined: Dec 2016
RE: (12C) Sum and Average
Thanks Dieter

You version is more refine.

Gamo
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)