 # Casio Calculator Programs

Ted Felix

These programs have been tested on my fx-7400G, CFX-9850G, and CFX-9850GC Plus. They appear to work fine, but no warranty is provided as usual. Test them thoroughly before using them for anything serious.

## Coding Tips

The characters used on the Casio calculators aren't easy to translate into a format that works on the Web. So there is a convention that is typically used:

`->` is the arrow key, not a hyphen and a greater-than sign.

`=>` is the "implies" operator found in the PRGM | JUMP menu.

`_` (the underscore) is the "display result command". It's the little triangle pointing southeast that you can find in the PRGM menu.

`[sqrt]` is the Square Root key.

`[ne]` is the "not equal" operator found in the PRGM | REL menu.

`[le]` is the "less than or equal" operator found in the PRGM | REL menu.

`E` is the exponent symbol. Press the [EXP] key.

`[a b/c]` is the fraction symbol which looks like a little lower right corner. Press the [a b/c] key.

Brian's page gives more detail.

## Number Guesser Game

Try to guess a number between 1 and 100. Press EXE twice when it says "-DISP-" to see the range, then make your guess.

```1->L 100->H Int (Ran#×100)->A Do L_ H_ ?->G G[ne]A=>"KEEP TRYING" G>A=>G->H G<A=>G->L LpWhile G[ne]A "GOT IT" ```

## Divisors

This program displays all the divisors of a number. Great for checking middle school math homework. Keep pressing EXE until it says DONE to see all the divisors.

```?->N For 1->D To [sqrt]N If N÷D=Int (N÷D) Then D_ N÷D_ IfEnd Next "DONE" ```

## Prime Factors

This program breaks a number down into its prime factors. Keep pressing EXE until it says DONE to see all the prime factors.

```?->N 2->D Do If N÷D=Int (N÷D) Then D_ N÷D->N 1->D IfEnd D+1->D LpWhile D[le][sqrt]N N_ "DONE" ```

## GCD/GCF and LCM

This one computes both the greatest common divisor (better known as the greatest common factor in middle school math) and the least common multiple using Euclid's algorithm. After the GCD is displayed, press EXE to see the LCM.

```?->A ?->B A×B->P While B[ne]0 B->T A-B×Intg (A÷B)->B T->A WhileEnd "GCD" A_ "LCM" P÷A ```

Note: I wasn't able to find a "modulo" operator on the Casio, so I used

`A-B×Intg (A÷B)`

## Decimal to Fraction

I noticed that my fx-7400G will do decimal to fraction conversions if you press the [F<->D] key. However, none of the other calculators seem to do this. So, I wrote the following program to help out. It's a fairly simple program, so it has limitations.

```?->N Int N->I Frac N->F For 1->D To 1000 F×D->N If Abs (Int (N+.5)-N)<1E-10×D Then Int (N+.5)->N Break IfEnd Next I[a b/c]N[a b/c]D[a b/c] ```

This is a really slow algorithm. Try entering .001. It will take a while. I've seen other decimal to fraction programs and I need to download one to see what sort of tricks I can use to improve this. I did come up with a variation that is very fast, but it has serious limitations that render it almost useless. Basically, if you multiply the decimal by 1E10, then put 1E10 on the other side of the fraction symbol, you use the calculator's fraction feature to convert decimal to fraction for you. For example:

```(.25×1E10)[a b/c]1E10 ```

## Solving Quadratic Equations

That Quadratic Formula sure is a pain to memorize, but it makes it really easy to program a calculator to solve quadratic equations for you. Forget about solving by factoring and completing the square. Just use this program.

```"QUADRATIC" "A"?->A "B"?->B "C"?->C B2-4AC->D If D<0 Then "NO SOLUTIONS" Stop IfEnd (-B+[sqrt]D)÷(2A)_ D>0=>(-B-[sqrt]D)÷(2A)_ "DONE" ```