PawCalc Example Programs

Last updated February 13, 2000. See the PawSoft web page for information on the latest version of PawCalc, or send e-mail to pawsoft@mail.com. Comments or bug-reports are welcome.

Some of the programs on this page are made by PawCalc users. All programs are available for your convenience, and they come with absolutely no warrenty of any kind. Use them at your own risk. That said, we hope you enjoy the programs.

If you have made a program for PawCalc and you want to have it displayed here, send us an email with a copy of the program and a short description.


Greatest Common Divisor

Author: Poul F. Williams
Date: February 13, 2000

This program computes the greatest common divisor of two numbers. For example, gcd(42,18) is 6.

gcd(x,y)
{
  let x := abs trunc x;
  let y := abs trunc y;

  local q, r;

  if x < y then
    let q := x;
    let x := y;
    let y := q;
  endif

  repeat
    let q := trunc( x / y );
    let r := x - q*y;
    let x := y;
    let y := r;
  until r = 0;

  return x;
}

Gas Milage

Author: Poul F. Williams
Date: February 12, 2000

These two programs convert gas milage from miles per gallon to kilometers per liter and vice versa.

mpg2kml( x )
{
  return x mi->km / 1 gal->l;
}

kml2mpg( x )
{
  return x km->mi / 1 l->gal;
}

Next Prime

Author: Rolf Muth
Date: January 24, 2000

This program calculates prime numbers, np(1) shows 2, and then with np(ans) every click on EXE gives the next prime.

np(zahl)
{
if zahl<2 then return 2; endif;
let zahl:= trunc zahl;
if frac ((zahl+1)/2) then
  let zahl:= zahl-1;
endif;
local teiler;
repeat
  let teiler:= 3;
  let zahl:= zahl+2;
  while (frac (zahl/teiler)) * (teiler*teilerzahl;
return zahl;
}

Next Divisor

Author: Rolf Muth
Date: January 24, 2000

ntl(120,0) gives the first number that divides 120 and then ntl(120,ans) gives with every click on EXE the next one up to 120 staying there.

ntl(zahl, teiler)
{
let zahl:= trunc abs zahl;
let teiler:= trunc abs teiler+1;
if zahl/2 > teiler then
  while frac (zahl/teiler) do
    let teiler:= teiler+1;
  endwhile;
  return teiler;
else
  return zahl;
endif;
}

Finansial Programs

Author: Poul F. Williams
Date: December 11, 1999

Compounded interest calculation program. It computes the value of a capital after a number of years given an annual interest in procent.

ci( capital, procent, year )
{
  return capital*(1 + procent/100)^year;
}

Present value calculation program. It computes the present value of a capital that is due in a number of years given an annual interest in procent.

pv( capital, procent, year )
{
  return capital / ((1 + procent/100)^year);
}

Annuity calculation program. It computes the yearly instalment on a loan payable in equal amounts.

an( capital, procent, year )
{
  local p := procent/100;
  local t := (1+p)^year;
  return capital * t * p / ( t - 1 );
}

Inflation calculation program. It computes how much the money value decreases due to inflation.

in( procent )
{
  return 100*procent / ( 100 + procent );
}

Copyright © 1999, 2000 Poul F. Williams. All Rights Reserved.
The programs on this page are copyright © of their respective authors.