output = title ++ captions ++ concat (map line [1..20])
title = cjustify 60 "A TABLE OF POWERS" ++ "\n\n"
captions = format "N" ++ concat (map caption [2..5]) ++ "\n"
caption i = format ("N^" ++ shownum i)
format = rjustify 12
line n = concat [format (show(n^i)) | i<-[1..5]] ++ "\n"
This prints a table of powers 2 to 5 of the numbers 1 to 20. To see the table, say
output
the result looks like this:
A TABLE OF POWERS
N N^2 N^3 N^4 N^5
1 1 1 1 1
2 4 8 16 32
3 9 27 81 243
4 16 64 256 1024
5 25 125 625 3125
6 36 216 1296 7776
7 49 343 2401 16807
8 64 512 4096 32768
9 81 729 6561 59049
10 100 1000 10000 100000
11 121 1331 14641 161051
12 144 1728 20736 248832
13 169 2197 28561 371293
14 196 2744 38416 537824
15 225 3375 50625 759375
16 256 4096 65536 1048576
17 289 4913 83521 1419857
18 324 5832 104976 1889568
19 361 6859 130321 2476099
20 400 8000 160000 3200000