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 Gauss:


       n       n(n + 1)
        k = ——————————
      k=1         2
  

Usage

  1. Enter the number n, for which you want to compute the Gauss sum.
  2. 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.

Resources

Labels

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

0 Cumulated sum
1 Counter for ISG function

Flags

9 Flag 9 is set if the integer number is greater than 999 when using the ISG version.

Program code

  Line          Code   Mnemonic

   000 {             } 
   001 {    42 21 11 } f LBL A
   002 {           9 } 9
   003 {           9 } 9
   004 {           9 } 9
   005 {    43 30  8 } g TEST x<y
   006 {       22  3 } GTO 3
   007 {       42 34 } f REG
   008 {          34 } x↔y
   009 {           1 } 1
   010 {          26 } EEX
   011 {           3 } 3
   012 {          16 } CHS
   013 {          20 } ×
   014 {           1 } 1
   015 {          26 } EEX
   016 {           5 } 5
   017 {          16 } CHS
   018 {          40 } +
   019 {       44  1 } STO 1
   020 {    42 21  1 } f LBL 1
   021 {    42  6  1 } f ISG 1
   022 {       22  2 } GTO 2
   023 {       45  0 } RCL 0
   024 {       43 32 } g RTN
   025 {    42 21  2 } f LBL 2
   026 {       45  1 } RCL 1
   027 {       43 44 } g INT
   028 {    44 40  0 } STO + 0
   029 {       22  1 } GTO 1
   030 {    42 21  3 } f LBL 3
   031 {    43  4  9 } g SF 9
   032 {       43 32 } g RTN
   033 {    42 21 12 } f LBL B
   034 {          36 } ENTER
   035 {          36 } ENTER
   036 {           1 } 1
   037 {          40 } +
   038 {          20 } ×
   039 {           2 } 2
   040 {          10 } ÷
   041 {       43 32 } g RTN