Data Structures | Defines | Functions

pyramid_of_numbers.c File Reference

#include <stdio.h>
Include dependency graph for pyramid_of_numbers.c:

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 Documentation

#define MAX_DIGITS   80

The maximum number of digits allowed in a big int.


Function Documentation

void copy_big_int ( const struct BigInt from,
struct BigInt to 
)

copy_big_int() copies a BigInt to another BigInt.

Parameters:
from The source where we want to copy from.
*to The target where we want to copy to.
void divide ( const struct BigInt big_int,
int  divisor,
struct BigInt big_result 
)

divide() multiplies a BigInt by an int.

Parameters:
big_int The BigInt to be divided.
divisor The int value by which we want to devide big_int.
*big_result The result of the division.
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.

void multiply ( const struct BigInt big_int,
int  factor,
struct BigInt big_result 
)

multiply() multiplies a BigInt by an int.

Parameters:
big_int The BigInt to be multiplied.
factor The int value which is multiplied by BigInt.
*big_result The result of the multiplication.
void print_big_int ( const struct BigInt big_int  ) 

print_big_int() prints a BigInt.

Parameters:
*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.

Parameters:
*str The string to be converted.
len Number of characters in string to be converted.
*big_int The converted string now as BigInt.
Returns:
The number of characters converted.
 All Data Structures Files Functions Variables Defines