diff options
Diffstat (limited to 'mat/euler/1/prog.c')
-rw-r--r-- | mat/euler/1/prog.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/mat/euler/1/prog.c b/mat/euler/1/prog.c new file mode 100644 index 0000000..f152200 --- /dev/null +++ b/mat/euler/1/prog.c @@ -0,0 +1,23 @@ +#include <stdio.h> +#include <stdlib.h> +int main (int argc, char ** argv) { + if (argc != 1+3) { + fprintf(stderr, "uporaba: %s <max> <a> [b c d e ...]\nprimer, ki do 1000 izpiše večkratnike 3 ali 5: %s 1000 3 5\n", argv[0], argv[0]); + return 1; + } + unsigned long int m = strtoll(argv[1], NULL, 10); + unsigned long int * n = malloc(sizeof(unsigned long int)*argc-2); + size_t i = 0; + size_t j = 0; + unsigned long int s = 0; // Seštevek + for (i = 0; i < argc-2; i++) + n[i] = strtoll(argv[i+2], NULL, 10); + for (i = 1; i < m; i++) + for (j = 0; j < argc-2; j++) + if (i % n[j] == 0) { + s = s + i; + break; // da štejemo samo enkrat + } + fprintf(stdout, "konec. seštevek je %ld.\n", s); + return 0; +} |