summaryrefslogtreecommitdiffstats
path: root/mat
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-12-08 00:18:37 +0100
committersijanec <sijanecantonluka@gmail.com>2020-12-08 00:18:37 +0100
commitbcb05e675c287755a2be90723fc214281f3c4278 (patch)
tree9911b49c064d8ff6e01387e6edda4ed8d04b36d8 /mat
parentadvent 4 fix, remove debug (diff)
downloadsola-gimb-2-bcb05e675c287755a2be90723fc214281f3c4278.tar
sola-gimb-2-bcb05e675c287755a2be90723fc214281f3c4278.tar.gz
sola-gimb-2-bcb05e675c287755a2be90723fc214281f3c4278.tar.bz2
sola-gimb-2-bcb05e675c287755a2be90723fc214281f3c4278.tar.lz
sola-gimb-2-bcb05e675c287755a2be90723fc214281f3c4278.tar.xz
sola-gimb-2-bcb05e675c287755a2be90723fc214281f3c4278.tar.zst
sola-gimb-2-bcb05e675c287755a2be90723fc214281f3c4278.zip
Diffstat (limited to 'mat')
-rw-r--r--mat/euler/15/NEDOKONCAN0
-rw-r--r--mat/euler/16/Makefile2
-rwxr-xr-xmat/euler/16/a.outbin0 -> 8600 bytes
-rw-r--r--mat/euler/16/mnozi.c31
-rw-r--r--mat/euler/16/prog.c30
5 files changed, 63 insertions, 0 deletions
diff --git a/mat/euler/15/NEDOKONCAN b/mat/euler/15/NEDOKONCAN
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mat/euler/15/NEDOKONCAN
diff --git a/mat/euler/16/Makefile b/mat/euler/16/Makefile
new file mode 100644
index 0000000..8278251
--- /dev/null
+++ b/mat/euler/16/Makefile
@@ -0,0 +1,2 @@
+default:
+ gcc prog.c -pedantic -I.
diff --git a/mat/euler/16/a.out b/mat/euler/16/a.out
new file mode 100755
index 0000000..25772a9
--- /dev/null
+++ b/mat/euler/16/a.out
Binary files differ
diff --git a/mat/euler/16/mnozi.c b/mat/euler/16/mnozi.c
new file mode 100644
index 0000000..f90cdbd
--- /dev/null
+++ b/mat/euler/16/mnozi.c
@@ -0,0 +1,31 @@
+#pragma once
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+int mnozi (unsigned long long int mnozi_s_tem, char * d, long int b) {
+ unsigned long long int carry = 0; // carry je pri množenju vedno pozitiven
+ unsigned long long int to = 0;
+ unsigned long long int za_napisati = 0;
+ for (b = b-1; b >= 0; b--) {
+ to = d[b] - '0';
+ za_napisati = to * mnozi_s_tem;
+ za_napisati = za_napisati + carry;
+ carry = 0;
+ if (za_napisati > 9) {
+ za_napisati = za_napisati - 10;
+ carry++;
+ }
+ d[b] = za_napisati + '0';
+ }
+ return 0;
+}
+#ifndef DISABLE_LIB_TESTS
+int main (int argc, char ** argv) {
+ unsigned long long int m = 2;
+ char d[] = "0000000000000000000000000000000000000000000000000000456";
+ int b = strlen(d);
+ mnozi(m, d, b);
+ fprintf(stdout, "test: %s\n", d);
+ return 0;
+}
+#endif
diff --git a/mat/euler/16/prog.c b/mat/euler/16/prog.c
new file mode 100644
index 0000000..5a2d7f3
--- /dev/null
+++ b/mat/euler/16/prog.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+#define DISABLE_LIB_TESTS
+#include <mnozi.c>
+#define MAX_SIRINA 80*(24-3) /* zapolnimo malo teminalsko okno */
+#define MAX_SIRINA_S "1680" /* = 80 * 21; nastavi tudi to za format stavek */
+int main (int argc, char ** argv) {
+ if (argc != 1+2) {
+ fprintf(stderr, "uporaba: %s <Številka> (^) <Številka>\nprimer za izračun 2^1000: %s 2 1000\n", argv[0], argv[0]);
+ return 1;
+ }
+ unsigned long long int n = strtoull(argv[1], NULL, 10);
+ unsigned long long int m = strtoull(argv[2], NULL, 10);
+ if (m == 0) {
+ fprintf(stderr, "KARKOLI NA NIČ JE ENA! (reci to računalniku)\n");
+ return 2;
+ }
+ char * z = malloc(sizeof(char)*(MAX_SIRINA + 1)); // + 1 za \0
+ unsigned int l = MAX_SIRINA;
+ unsigned long long int s = 0; // Seštevek števk
+ sprintf(z, "%0" MAX_SIRINA_S "llu", n);
+ z[MAX_SIRINA] = '\0';
+ for (; m > 1; m--)
+ // fprintf(stderr, "\rpreostane še %llu operacij ...", m);
+ mnozi (n, z, l);
+ for (m = 0; m < MAX_SIRINA; m++) // sicer je m itak že 0 ampak okej
+ s = s + (z[m] - '0');
+ fprintf(stdout, "\rkonec računanja. seštevek števk v rezultatu je %llu, število je\n%s\n", s, z);
+ return 0;
+}