Created
April 22, 2011 08:47
-
-
Save zrbecker/936303 to your computer and use it in GitHub Desktop.
Euler 8
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 <stdio.h> | |
#include <stdlib.h> | |
void readfile(char *file, int *buffer, int size, int *read) { | |
FILE *f = fopen(file, "r"); | |
char c; | |
int pos; | |
while ( (c = getc(f)) != EOF && pos < size - 1) { | |
if (c >= '0' && c <= '9') | |
buffer[pos++] = c - '0'; | |
} | |
*read = pos; | |
fclose(f); | |
} | |
int main(int argc, char **argv) { | |
int buffer[10000]; | |
int read; | |
readfile("e8.txt", buffer, 10000, &read); | |
int i; | |
int largest = 1, p; | |
for (i = 0; i < read - 5; ++i) { | |
p = buffer[i] * buffer[i + 1] * buffer[i + 2] * buffer[i + 3] * buffer[i + 4]; | |
if (p > largest) | |
largest = p; | |
} | |
printf("%d\n", largest); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment