1 Function get_length_of_the_first_number() Which Returns Integer32 Is External;
2 Function get_digit_of_the_first_number_at(Integer32 index) Which Returns Character Is External;
3 Function get_length_of_the_second_number() Which Returns Integer32 Is External;
4 Function get_digit_of_the_second_number_at(Integer32 index) Which Returns Character Is External;
5 Function putc(Character char) Which Returns Nothing Is External;
6 Function logString(PointerToCharacter string) Which Returns Nothing Is External;
7
8 Character matrix[100*100];
9 Function f(Integer16 i, Integer16 j) Which Returns Integer32 Does
10 Return i * 100 + j;
11 EndFunction
12
13 Character result[100];
14
15 Function get_length_of_the_result() Which Returns Integer16 Does
16 Integer16 i := 0;
17 While i < 100 Loop
18 If result[i]=0 Then
19 Return i;
20 EndIf
21 i += 1;
22 EndWhile
23 Return i;
24 EndFunction
25
26 Function prepend_a_character_to_the_result(Character char) Which Returns Nothing Does
27 Integer16 i := get_length_of_the_result() + 1;
28 While i > 0 Loop
29 result[i]:=result[i - 1];
30 i -= 1;
31 EndWhile
32 result[0] := char;
33 EndFunction
34
35 Function multiply() Which Returns Nothing Does
36 Integer32 i := 0, j := 0;
38 While i < get_length_of_the_second_number() Loop
39 j := 0;
40 While j < get_length_of_the_first_number() + get_length_of_the_second_number() + 1 Loop
41 matrix[f(i,j)] := ' ';
42 j += 1;
43 EndWhile
44 i += 1;
45 EndWhile
46 logString("The matrix is successfully filled with spaces.");
47
48 Integer32 pointer_to_the_digit_in_the_second_number := 0;
50 While pointer_to_the_digit_in_the_second_number < get_length_of_the_second_number() Loop
51 Integer16 carry := 0,
52 pointer_to_the_matrix_column := get_length_of_the_first_number() +
53 pointer_to_the_digit_in_the_second_number + 1;
54 Integer16 pointer_to_the_digit_in_the_first_number := get_length_of_the_first_number() - 1;
55 While pointer_to_the_digit_in_the_first_number >= 0 Loop
56 Integer16 product :=
57 (get_digit_of_the_first_number_at(pointer_to_the_digit_in_the_first_number) - '0') *
58 (get_digit_of_the_second_number_at(pointer_to_the_digit_in_the_second_number) - '0') +
59 carry;
60 matrix[f(pointer_to_the_digit_in_the_second_number, pointer_to_the_matrix_column)]
61 := mod(product, 10) + '0';
62 If product >= 10 Then
63 carry := product / 10;
64 Else
65 carry := 0;
66 EndIf
67 pointer_to_the_matrix_column -= 1;
68 pointer_to_the_digit_in_the_first_number -= 1;
69 EndWhile
70 If carry Then
71 matrix[f(pointer_to_the_digit_in_the_second_number,pointer_to_the_matrix_column)] :=
72 mod(carry, 10) + '0';
73 EndIf
74 If carry >= 10 Then
75 pointer_to_the_matrix_column -= 1;
76 matrix[f(pointer_to_the_digit_in_the_second_number, pointer_to_the_matrix_column)] :=
77 carry / 10 + '0';
78 EndIf
79 pointer_to_the_digit_in_the_second_number += 1;
80 EndWhile
81 logString("The matrix is now filled with the products of the first number and the digits of the second.");
82
83 result[0]:=0;
85 Integer16 carry := 0;
86 i := get_length_of_the_first_number() + get_length_of_the_second_number();
87 While i >= 0 Loop
88 Integer32 sum := carry;
89 j := 0;
90 While j < get_length_of_the_second_number() Loop
91 If not(matrix[f(j, i)] = ' ') Then
92 sum += matrix[f(j, i)] - '0';
93 EndIf
94 j += 1;
95 EndWhile
96 prepend_a_character_to_the_result(mod(sum, 10) + '0');
97 carry := sum / 10;
98 i -= 1;
99 EndWhile
100 If carry Then
101 prepend_a_character_to_the_result(carry + '0');
102 EndIf
103 logString("The matrix is now summed up and the product of the two numbers is calculated.");
104
105 i := 0;
107 While result[i] = '0' Loop
108 result[i] := ' ';
109 i += 1;
110 EndWhile
111 logString("The trailing zeros in the result are now replaced by spaces.");
112
113 putc(' ');
115 putc(' ');
116 i := 0;
117 While i < get_length_of_the_first_number() Loop
118 putc(get_digit_of_the_first_number_at(i));
119 i += 1;
120 EndWhile
121 putc('*');
122 i := 0;
123 While i < get_length_of_the_second_number() Loop
124 putc(get_digit_of_the_second_number_at(i));
125 i += 1;
126 EndWhile
127 putc('\n');
128
129 i := 0;
130 While i < get_length_of_the_first_number() + get_length_of_the_second_number() + 1 + 2 Loop
131 putc('-');
132 i += 1;
133 EndWhile
134 putc('\n');
135
136 i := 0;
137 While i < get_length_of_the_second_number() Loop
138 j := 0;
139 While j < get_length_of_the_first_number() + get_length_of_the_second_number() + 1 Loop
140 putc(matrix[f(i,j)]);
141 j += 1;
142 EndWhile
143 putc('\n');
144 i += 1;
145 EndWhile
146
147 i := 0;
148 While i < get_length_of_the_first_number() + get_length_of_the_second_number() + 1 Loop
149 putc('-');
150 i += 1;
151 EndWhile
152 putc('\n');
153
154 i := 0;
155 While result[i] Loop
156 putc(result[i]);
157 i += 1;
158 EndWhile
159 putc('\n');
160
161 logString("The result should be visible on the screen now!");
162 EndFunction
163