summaryrefslogtreecommitdiffstats
path: root/mat/euler/2/prog.c
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/prog.c
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/prog.c')
-rw-r--r--mat/euler/2/prog.c33
1 files changed, 33 insertions, 0 deletions
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;
+}