Back to table

Simple Summation Program

The following is a valid µOCCAM program that performs I/O. A simple program that takes in two integers and outputs the numbers from the first to the last and then sums them and outputs the sum.

Program file: /public/cs3/web/ipptests/summation.io


INT from:
INT to:
INT sum = 0:

SEQ
  stdin ? from
  stdin ? to

  WHILE from > to

    SEQ
      stdout ! from 
      sum:=sum+from
      from:= from - 1


  stdout ! sum

When provided with this input: /public/cs3/web/ipptests/summation.in

10
0

it should generate the following output: /public/cs3/web/ipptests/summation.out

==> 10
==> 9
==> 8
==> 7
==> 6
==> 5
==> 4
==> 3
==> 2
==> 1
==> 55