The Ada Program: formula.adb
1 -- formula.adb: print a table of the sum 1..N of powers
2
3 with Ada.Text_IO, Ada.Integer_Text_IO;
4 use Ada;
5
6 procedure Formula is
7
8 NN1: Integer;
9
10 begin
11
12 Text_IO.Put_Line (" n sum k sum k*k sum k**3 sum k**4");
13 Text_IO.Put_Line ("--- ----- ------- -------- --------");
14
15 for N in 1 .. 40 loop
16 NN1 := N * (N+1);
17 Integer_Text_IO.Put (N, Width=>3);
18 Integer_Text_IO.Put (NN1/2, Width=>8);
19 Integer_Text_IO.Put (NN1*(2*N+1)/6, Width=>9);
20 Integer_Text_IO.Put (NN1*NN1/4, Width=>10);
21 Integer_Text_IO.Put (NN1*(2*N+1)*(3*N**2+3*N-1)/30, Width=>11);
22 Text_IO.New_Line;
23 end loop;
24
25 end Formula;