Problem 16 solution
More...
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
|
int | main (int argc, char **argv) |
| Main function. More...
|
|
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Main function.
14 const double tmp = log(10) / log(2);
15 unsigned long MAX_NUM_DIGITS;
18 int N = 1000, sum = 0;
23 MAX_NUM_DIGITS = (N + tmp) / tmp;
25 digits =
calloc(MAX_NUM_DIGITS,
sizeof(uint8_t));
30 perror(
"Unable to allocate memory!");
34 for (
int i = 0; i < N; i++)
37 for (
int j = 0; j < MAX_NUM_DIGITS; j++)
39 digits[j] = (digits[j] << 1) + carry;
57 for (
int i = MAX_NUM_DIGITS - 1; i >= 0; i--) putchar(digits[i] + 0x30);
58 printf(
"\n\t Sum: %d\t Num. digits: %lu\n", sum, MAX_NUM_DIGITS);
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition: malloc_dbg.h:26
#define calloc(elemCount, elemSize)
This macro replace the standard calloc function with calloc_dbg.
Definition: malloc_dbg.h:22