summaryrefslogtreecommitdiffstats
path: root/mat/euler/2
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-12-03 17:08:39 +0100
committersijanec <sijanecantonluka@gmail.com>2020-12-03 17:08:39 +0100
commit190507a0a05e7a6292b41bec529910ecfcbb69fb (patch)
tree20105249580655bc8b5bf47ea9ebf0e543fa06e7 /mat/euler/2
parentnaredil 8. nalogo eulerja (diff)
downloadsola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.tar
sola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.tar.gz
sola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.tar.bz2
sola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.tar.lz
sola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.tar.xz
sola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.tar.zst
sola-gimb-2-190507a0a05e7a6292b41bec529910ecfcbb69fb.zip
Diffstat (limited to 'mat/euler/2')
-rw-r--r--mat/euler/2/Makefile2
-rwxr-xr-xmat/euler/2/a.outbin0 -> 8432 bytes
-rw-r--r--mat/euler/2/prog.c33
3 files changed, 35 insertions, 0 deletions
diff --git a/mat/euler/2/Makefile b/mat/euler/2/Makefile
new file mode 100644
index 0000000..2def8af
--- /dev/null
+++ b/mat/euler/2/Makefile
@@ -0,0 +1,2 @@
+default:
+ gcc prog.c
diff --git a/mat/euler/2/a.out b/mat/euler/2/a.out
new file mode 100755
index 0000000..5b7faf9
--- /dev/null
+++ b/mat/euler/2/a.out
Binary files differ
diff --git a/mat/euler/2/prog.c b/mat/euler/2/prog.c
new file mode 100644
index 0000000..607417c
--- /dev/null
+++ b/mat/euler/2/prog.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdlib.h>
+int main (int argc, char ** argv) {
+ if (argc != 1+2) {
+ fprintf(stderr, "uporaba: %s <max> <delitelj>\nprimer, ki sešteje vsa liha fibonačijeva števila do 2M: %s 2000000 -2\nče je deljenec negativen, se seštejejo števila, ki NISO deljiva z deliteljem\n", argv[0], argv[0]);
+ return 1;
+ }
+ unsigned long int s = strtoll(argv[1], NULL, 10); // makSimalno
+ unsigned long int d = strtoll(argv[2], NULL, 10); // Delitelj
+ unsigned short int o = (llabs(d) == d);
+ d = llabs(d);
+ unsigned long int i = 1;
+ unsigned long int j = 2;
+ unsigned long int c = 0; // Carry
+ unsigned long int e = 0; // sEštevek
+ while (i <= s) {
+ fprintf(stderr, "i = %ld, seštevek = %ld\n", i, e);
+ if (o) {
+ if (i % d == 0) {
+ e = e + i;
+ }
+ } else {
+ if (i % d != 0) {
+ e = e + i;
+ }
+ }
+ c = i + j;
+ i = j;
+ j = c;
+ }
+ fprintf(stdout, "\rseštevek števil do %ld, ki z %ld %s deljiva: %ld\n", s, d, o ? "so" : "niso", e);
+ return 0;
+}