Last active
December 22, 2015 10:48
-
-
Save Cloudef/6460989 to your computer and use it in GitHub Desktop.
pew pew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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