#include <stdio.h>
Data Structures | |
| struct | BigInt |
Defines | |
| #define | MAX_DIGITS 80 |
| The maximum number of digits allowed in a big int. | |
Functions | |
| int | strtobig_int (const char *str, int len, struct BigInt *big_int) |
| void | print_big_int (const struct BigInt *big_int) |
| void | multiply (const struct BigInt *big_int, int factor, struct BigInt *big_result) |
| void | divide (const struct BigInt *big_int, int divisor, struct BigInt *big_result) |
| void | copy_big_int (const struct BigInt *from, struct BigInt *to) |
| int | main (int argc, char *argv[]) |
| #define MAX_DIGITS 80 |
The maximum number of digits allowed in a big int.
copy_big_int() copies a BigInt to another BigInt.
| from | The source where we want to copy from. | |
| *to | The target where we want to copy to. |
| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
main() reads the base number from which the pyramid has to be calculated into an array of char. The max. length of this number is MAX_DIGITS. The number is checked to contain only digits. If not the program exits. Then the inputted number is converted into a big int by calling the function strtobig_int(). After the conversion the tower is calculated by calling the functions multiply(), print_big_int(), and copy_big_int() consecutively from 2 to 9 and then again with divide() instead of multiply() from 2 to 9.
multiply() multiplies a BigInt by an int.
| void print_big_int | ( | const struct BigInt * | big_int | ) |
print_big_int() prints a BigInt.
| *big_int | The BigInt to be printed. |
| int strtobig_int | ( | const char * | str, | |
| int | len, | |||
| struct BigInt * | big_int | |||
| ) |
strtobig_int converts a string into a BigInt. If strtobig_int runs against a character not between '0' and '9' the conversion stops at this point.
| *str | The string to be converted. | |
| len | Number of characters in string to be converted. | |
| *big_int | The converted string now as BigInt. |
1.7.0