From bcb05e675c287755a2be90723fc214281f3c4278 Mon Sep 17 00:00:00 2001 From: sijanec Date: Tue, 8 Dec 2020 00:18:37 +0100 Subject: euler16 --- mat/euler/15/NEDOKONCAN | 0 mat/euler/16/Makefile | 2 ++ mat/euler/16/a.out | Bin 0 -> 8600 bytes mat/euler/16/mnozi.c | 31 +++++++++++++++++++++++++++++++ mat/euler/16/prog.c | 30 ++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 mat/euler/15/NEDOKONCAN create mode 100644 mat/euler/16/Makefile create mode 100755 mat/euler/16/a.out create mode 100644 mat/euler/16/mnozi.c create mode 100644 mat/euler/16/prog.c (limited to 'mat') diff --git a/mat/euler/15/NEDOKONCAN b/mat/euler/15/NEDOKONCAN new file mode 100644 index 0000000..e69de29 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 Binary files /dev/null and b/mat/euler/16/a.out 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 +#include +#include +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 +#include +#define DISABLE_LIB_TESTS +#include +#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; +} -- cgit v1.2.3