From c9a6a1b8a3ec380adaf74f0ce8d650e97e38f474 Mon Sep 17 00:00:00 2001 From: mjfernez Date: Sun, 9 Feb 2020 15:43:30 -0500 Subject: added Power Digit Sum solution in C --- 16-Power-Digit-Sum/sumexp | Bin 0 -> 16800 bytes 16-Power-Digit-Sum/sumexp.c | 24 ++++++++++++++++++++++++ reworking/WARNING | 1 + reworking/sumexp.c | 15 --------------- 4 files changed, 25 insertions(+), 15 deletions(-) create mode 100755 16-Power-Digit-Sum/sumexp create mode 100644 16-Power-Digit-Sum/sumexp.c create mode 100644 reworking/WARNING delete mode 100644 reworking/sumexp.c diff --git a/16-Power-Digit-Sum/sumexp b/16-Power-Digit-Sum/sumexp new file mode 100755 index 0000000..854ac69 Binary files /dev/null and b/16-Power-Digit-Sum/sumexp differ diff --git a/16-Power-Digit-Sum/sumexp.c b/16-Power-Digit-Sum/sumexp.c new file mode 100644 index 0000000..7d471ab --- /dev/null +++ b/16-Power-Digit-Sum/sumexp.c @@ -0,0 +1,24 @@ +#include +#include +#include + +// Compile Notes: use `gcc .c -lgmp` + + +int main(){ + mpz_t num, remainder; + unsigned long sum = 0; + mpz_init(num); + mpz_init(remainder); + // From docs, this assigns the value num to the value 2^1000 + mpz_ui_pow_ui(num, 2, 1000); + + // mpz_sgn returns 1 if positive, 0 if 0, -1 if negative + while(mpz_sgn(num)){ + sum += mpz_mod_ui(remainder, num, 10); + mpz_fdiv_q_ui(num, num, 10); + } + printf("%lu\n", sum); + return 0; +} + diff --git a/reworking/WARNING b/reworking/WARNING new file mode 100644 index 0000000..5ddb825 --- /dev/null +++ b/reworking/WARNING @@ -0,0 +1 @@ +The code here doesn't work. Please don't expect it to. diff --git a/reworking/sumexp.c b/reworking/sumexp.c deleted file mode 100644 index 8078909..0000000 --- a/reworking/sumexp.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -// Compile Notes: use `gcc .c -lgmp` - -mpz_t num; - -int main(){ - - // From docs, this assigns num the value of (op1*2) ^ op2 - mpz_mul_2exp(num, ) - return 0; -} - -- cgit v1.2.3