From 6d9781765daf3ac1e80f43c4a0d38d07261c4721 Mon Sep 17 00:00:00 2001 From: sijanec Date: Sat, 5 Dec 2020 15:35:38 +0100 Subject: 13. naloga --- mat/euler/13/dodaj.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 mat/euler/13/dodaj.c (limited to 'mat/euler/13/dodaj.c') 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 +#include +#include +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 -- cgit v1.2.3