EasyManua.ls Logo

HP 39gII - Page 280

HP 39gII
355 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
270 Programming
Evaluate test. If result is true (non 0), executes the
commands, and repeat.
Example: A perfect number is one that is equal to the sum
of all its proper divisors. For example, 6 is a perfect
number because 6 = 1+2+3. This function returns true
when its argument is a perfect number.
Example:
EXPORT ISPERFECT(n)
BEGIN
LOCAL d, sum;
2
d;
1
sum;
WHILE sum < = n AND d < n DO
IF irem(n,d)==0 THEN
sum+d
sum;
END;
d+1
d;
END;
RETURN sum==n;
END;
This program displays all the perfect numbers up to
1000:
EXPORT PERFECTNUMS()
BEGIN
LOCAL k;
FOR k FROM 2 TO 1000 DO
IF ISPERFECT(k) THEN
MSGBOX(k+" is perfect, press OK");
END;
END;
END;

Table of Contents

Other manuals for HP 39gII

Related product manuals