Algorithms_in_C
1.0.0
Set of algorithms implemented in C.
|
Problem 20 solution More...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Data Structures | |
struct | _big_int |
Typedefs | |
typedef struct _big_int | big_int |
Functions | |
big_int * | add_digit (big_int *digit, char value) |
char | remove_digits (big_int *digit, int N) |
int | main (int argc, char **argv) |
Problem 20 solution
Implementation uses a custom big_int
structure that can store arbitrarilty large integer numbers.
Function that allocates memory to add another digit at the MSB
int main | ( | int | argc, |
char ** | argv | ||
) |
Main function
sum digits on the last iteration this avoid having another loop over all digits
Notice that in the loop above, we make sure that at the end of the loop, ptr is pointing to the last digit. Thus we can avoid using another loop.
char remove_digits | ( | big_int * | digit, |
int | N | ||
) |
Function to remove digits preceeding the current digit.