Professional Documents
Culture Documents
Algo Comp Documentation 11
Algo Comp Documentation 11
1 Problem formulation
The aim of the program is to calculate and . Since we do not know the
n! nn
size of , we cannot use built types like unsigned integers or long integers
n
to store results of calculations. This is due to limitation of these built types
that is if the result is more than maximum integer number (depends on the
system architecture), it becomes a very small integer. That is why it is
better to use other ways for storing big numbers.
1/6
methods for operating on digits (reading and creating lists of digits,
addition, multiplication).
Data Representation:
bigNum
struct digit {
int d;
digit *next;
digit *prev;
};
digit *head;
digit *tail;
2/6
Addition:
We start addition from taking two bigNum numbers N1 and N2. Then we
take the first (the least significant) digits and define them as N1digit and
N2digit. We also define result(= 0) and initialize a carry to 0 - a flag
denoting that the sum of two digits is greater than 9 (0 – means no
correction is needed, 1 – correction is needed). In the loop (until the end of
the first number is reached) we calculate the result of adding 2 digits using
a formula : result = carry + N1digit + N2digit. If the result is greater than 9
we set carry to 1 and change the result to result – 10, otherwise carry is
set to 0. Then we change the current digit of N1 to result. If N1 does not
have the next digit and carry = 1, we add 1 to N1 (we add 1 as the most
significant digit). In the case of reaching the end of N2 and carry = 0 we
end addition, otherwise we continue the algorithm.
3/6
Multiplication:
4/6
the last digit of N1) we compute the result of multiplication of 2 digits and
store it in a variable n: n = carry + (N1digit * N2digit). If n is greater than
9, carry is set to n / 10 (integer division) and n % 10 is added to
currentSum (we add n to the current number). If we reach the end of N1,
we add carry to currentSum. Otherwise if n is less or equal to 9, we set
carry to 0 and add n to currentSum. Then we take the next digit of N1 go
again to the second loop. When we reach the end of N1 we check if the
variable result stores any value. If not we set result to currentSum,
otherwise the result is set to the sum of result and CurrentSum. Then we
take the next digit of N2 and go to the first loop.
- access to memory
- addition
- assignment
- comparison
- memory allocation
- memory deallocation
- multiplication
7 Format of results
In case of the results of algorithms, they will be stored in a file. Moreover,
there will be a simple GUI to represent these results.
5/6
The numbers of elementary operations will be exported to a csv file.
9 Illustration of results
The program will be chosen later (maybe Excel, Matlab or R).
6/6