summaryrefslogtreecommitdiffstats
path: root/mat/euler/13/dodaj.c
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-12-05 15:35:38 +0100
committersijanec <sijanecantonluka@gmail.com>2020-12-05 15:35:38 +0100
commit6d9781765daf3ac1e80f43c4a0d38d07261c4721 (patch)
treeceb1d414ee8752469ed35f1afc55c3e74168a205 /mat/euler/13/dodaj.c
parent12. naloga (diff)
downloadsola-gimb-2-6d9781765daf3ac1e80f43c4a0d38d07261c4721.tar
sola-gimb-2-6d9781765daf3ac1e80f43c4a0d38d07261c4721.tar.gz
sola-gimb-2-6d9781765daf3ac1e80f43c4a0d38d07261c4721.tar.bz2
sola-gimb-2-6d9781765daf3ac1e80f43c4a0d38d07261c4721.tar.lz
sola-gimb-2-6d9781765daf3ac1e80f43c4a0d38d07261c4721.tar.xz
sola-gimb-2-6d9781765daf3ac1e80f43c4a0d38d07261c4721.tar.zst
sola-gimb-2-6d9781765daf3ac1e80f43c4a0d38d07261c4721.zip
Diffstat (limited to 'mat/euler/13/dodaj.c')
-rw-r--r--mat/euler/13/dodaj.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/mat/euler/13/dodaj.c b/mat/euler/13/dodaj.c
new file mode 100644
index 0000000..d1fbb59
--- /dev/null
+++ b/mat/euler/13/dodaj.c
@@ -0,0 +1,38 @@
+#pragma once
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+int dodaj (const char * c, char * d, long int a, long int b) {
+ unsigned long long int carry = 0; // carry je pri seštevanju vedno pozitiven
+ long int diff = b-a;
+ unsigned long long int dodajmo_tole = 0;
+ unsigned long long int temu = 0;
+ for (b = b-1; b >= 0; b--) {
+ if (b-diff >= 0) {
+ dodajmo_tole = c[b-diff] - '0';
+ } else {
+ dodajmo_tole = 0;
+ }
+ temu = d[b] - '0';
+ dodajmo_tole = dodajmo_tole + carry;
+ carry = 0;
+ if (temu + dodajmo_tole > 9) {
+ dodajmo_tole = (temu + dodajmo_tole) - 10;
+ temu = 0;
+ carry++;
+ }
+ d[b] = temu + dodajmo_tole + '0';
+ }
+ return 0;
+}
+#ifndef DISABLE_LIB_TESTS
+int main (int argc, char ** argv) {
+ char c[] = "37107287533902102798797998220837590246510135740250";
+ char d[] = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000";
+ int a = strlen(c);
+ int b = strlen(d);
+ dodaj(c, d, a, b);
+ fprintf(stdout, "test: %s\n", d);
+ return 0;
+}
+#endif