Little Gauss for the HP-15C
Description
This program computes the sum of the numbers between 1 and a given integer n.
A problem well known as 'Little Gauss'. Ask your preferred Internet search engine if you have not heard about 'Little Gauss'.
The program provides two solutions for the problem. First a brute force algorithm adding one number after the other. This version uses the internal HP-15C function ISG. Secondly the program provides the original formula found by Carl Friedrich Gauss:
n n(n + 1)
∑ k = ——————————
k=1 2
- Enter the number
n, for which you want to compute the Gauss sum.
- Press f A to run the ISG version
or
press f B to run the original formula.
Due to the limitations of the ISG function, n must be less than 1000 when using this version.
Program Resources
Labels
| Name |
Description |
|
| A |
Little Gauss using built in function ISG |
|
| B |
Little Gauss using the formula |
|
| 1 |
Start of ISG sub program |
|
| 2 |
Sub program to sum up the numbers |
|
| 3 |
Set flag 9 (blinking) in case of error |
|
Storage Registers
| Name |
Description |
|
| 0 |
Cumulated sum |
|
| 1 |
Counter for ISG function |
|
Flags
| Number |
Description |
|
| 9 |
Flag 9 is set if the integer number is greater than 999 when using the ISG version. |
|
Program
| Line |
Display |
Key Sequence |
|
Line |
Display |
Key Sequence |
|
| 000 |
|
|
|
021 |
42, 6, 1 |
f ISG 1 |
|
| 001 |
42,21,11 |
f LBL A |
|
022 |
22 2 |
GTO 2 |
|
| 002 |
9 |
9 |
|
023 |
45 0 |
RCL 0 |
|
| 003 |
9 |
9 |
|
024 |
43 32 |
g RTN |
|
| 004 |
9 |
9 |
|
025 |
42,21, 2 |
f LBL 2 |
|
| 005 |
43,30, 8 |
g TEST x<y |
|
026 |
45 1 |
RCL 1 |
|
| 006 |
22 3 |
GTO 3 |
|
027 |
43 44 |
g INT |
|
| 007 |
42 34 |
f REG |
|
028 |
44,40, 0 |
STO + 0 |
|
| 008 |
34 |
x↔y |
|
029 |
22 1 |
GTO 1 |
|
| 009 |
1 |
1 |
|
030 |
42,21, 3 |
f LBL 3 |
|
| 010 |
26 |
EEX |
|
031 |
43, 4, 9 |
g SF 9 |
|
| 011 |
3 |
3 |
|
032 |
43 32 |
g RTN |
|
| 012 |
16 |
CHS |
|
033 |
42,21,12 |
f LBL B |
|
| 013 |
20 |
× |
|
034 |
36 |
ENTER |
|
| 014 |
1 |
1 |
|
035 |
36 |
ENTER |
|
| 015 |
26 |
EEX |
|
036 |
1 |
1 |
|
| 016 |
5 |
5 |
|
037 |
40 |
+ |
|
| 017 |
16 |
CHS |
|
038 |
20 |
× |
|
| 018 |
40 |
+ |
|
039 |
2 |
2 |
|
| 019 |
44 1 |
STO 1 |
|
040 |
10 |
÷ |
|
| 020 |
42,21, 1 |
f LBL 1 |
|
041 |
43 32 |
g RTN |
|