Skip to content

Instantly share code, notes, and snippets.

@Cloudef
Last active December 22, 2015 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Cloudef/6460989 to your computer and use it in GitHub Desktop.
Save Cloudef/6460989 to your computer and use it in GitHub Desktop.
pew pew
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(int argc, char **argv) {
long int numbers[5];
long int highest = 0;
if (argc < 2 || strlen(argv[1]) < 5) {
fprintf(stderr, "5 digits minimum input string must be given\n");
return EXIT_FAILURE;
}
for (char *c = argv[1], *s = c; *c; ++c) {
if (!isdigit(*c)) {
fprintf(stderr, "Input string contains characters\n");
return EXIT_FAILURE;
}
numbers[c-s] = *c - '0';
if (c-s == 4) {
long int result = numbers[0];
for (int i = 1; i < 5; ++i) result *= numbers[i];
if (result > highest) highest = result;
c = s++;
}
}
printf("%ld\n", highest);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment