for i ← 1 to n do
read x
s ← s + x
output s
Informal
Read a, b, c
max ← a
If b > max then max ← b
If c > max then max ← c
Print max
Formal
input: n ≥ 0
output: n!
p ← 1
for i ← 2 to n do
p ← p · i
return p
Pseudocode
for i ← 1 to n do
read x
s ← s + x
output s
Java
for (int i=0; i<n; i++) {
int x = sc.nextInt();
s = s + x;
}
System.out.println(s);
Math-friendly:
input: a₁…aₙ
s ← 0
for i ← 1..n do
s ← s + aᵢ
output s
General audience:
Read a list of numbers
Add them up
Print the total
Can you do better?
You’re playing a dice game.
How can you find your chances of winning?