diff options
Diffstat (limited to 'mat/advent')
-rw-r--r-- | mat/advent/7/Makefile | 2 | ||||
-rwxr-xr-x | mat/advent/7/a.out | bin | 0 -> 8432 bytes | |||
-rw-r--r-- | mat/advent/7/prog.c | 31 |
3 files changed, 33 insertions, 0 deletions
diff --git a/mat/advent/7/Makefile b/mat/advent/7/Makefile new file mode 100644 index 0000000..ee0ed1a --- /dev/null +++ b/mat/advent/7/Makefile @@ -0,0 +1,2 @@ +default: + gcc -pedantic prog.c diff --git a/mat/advent/7/a.out b/mat/advent/7/a.out Binary files differnew file mode 100755 index 0000000..66f1e58 --- /dev/null +++ b/mat/advent/7/a.out diff --git a/mat/advent/7/prog.c b/mat/advent/7/prog.c new file mode 100644 index 0000000..7549d6b --- /dev/null +++ b/mat/advent/7/prog.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <stdlib.h> +/* opozorilo za prihodnost: + * to je zelo slab način za rešitev naloge. prosim, naredi mi uslugo in ga ne uporabljaj! + * -- a, 2020 */ +int main (int argc, char ** argv) { + if (argc != 1+1) { + fprintf(stderr, "uporaba: %s <številka>\nprimer: %s 300\n", argv[0], argv[0]); + return 1; + } + unsigned long int b = strtol(argv[1], NULL, 10); + unsigned long int x = b; + unsigned long int y = x; + unsigned long int z = x; + unsigned long long int i = 0; + unsigned long long int r = 0; + unsigned long long int s = 0; /* število najdenih in zapiSanih trojk */ + for (x = b; x > 0; x--) { + for (y = x; y > 0; y--) { + for (z = y; z > 0; z--) { + r++; + /* fprintf(stderr, "sum = %lu\n", x+y+z); */ + if ((x+y+z) % 3 == 0) { + s++; + } + } + } + } + fprintf(stdout, "\rkonec: našel sem skupno %llu trojk, r==%llu.\n", s, r); + return 0; +} |