Previous topic |
Ada Home Page |
Index
Nested loops
Print the times table for the numbers 1..10
User interface
1 2 3 4 5 6 7 8 9 10
1 1 2 3 4 5 6 7 8 9 10
2 2 4 6 8 10 12 14 16 18 20
3 3 6 9 12 15 18 21 24 27 30
4 4 8 12 16 20 24 28 32 36 40
5 5 10 15 20 25 30 35 40 45 50
6 6 12 18 24 30 36 42 48 54 60
7 7 14 21 28 35 52 49 56 63 70
8 8 16 24 32 40 48 56 64 72 80
9 9 18 27 36 45 54 63 72 81 90
10 10 20 30 40 50 60 70 80 90 100
Algorithm
1.0 print heading
1.1 while not all columns done
1.1.1 print column number
2.0 print table; for each row
2.1 print row
2.1.1 print row number
2.1.2 for each column
2.1.2.1 print column number
Program
---------------------------------------------------------
-- times.a - produce a 10x10 times table
---------------------------------------------------------
with TEXT_IO; use TEXT_IO;
procedure times is
-- declare integer I/I library
package int_io is new TEXT_IO.INTEGER_IO( INTEGER);
use int_io;
-- declare any constants and variables required
size: constant integer := 10;
---------------------------------------------------------
-- times program code
---------------------------------------------------------
begin
put(" "); -- heading of table
for i in 1..size loop
put(i,WIDTH=>5);
end loop;
new_line;
for row in 1..size loop -- each row of table
put(row,WIDTH=>5);
for col in 1..size loop -- each column of table put(col*row,WIDTH=>5);
end loop;
new_line;
end loop;
end times;
Previous topic |
Ada Home Page |
Index
c-lokan@adfa.oz.au / 14 Feb 96