Are there any zeros in the list?
If not, then an improvement would be to multiply the first 5 only, and then divide by the previous first of five and multiply by the new last each time.
e.g. With the list 7 3 6 7 3 9 you would perform:
currentMax = a = 7 * 3 * 6 * 7 * 3
currentMax = max ( currentMax, a * 9 / 7 )
rather than:
currentMax = max ( currentMax, 3 * 6 * 7 * 3 * 9 )
Also, you're doing unnecessary loops. A char is merely another integer that encodes different ASCII characters, so there's no danger or ambiguity in the replacement loop:
1 2 3 4
|
for (int i = 0; file.good(); i++)
{
x[i] = file.get() - '0';
}
|
Honestly, I'm surprised the program isn't crashing, when declare an array you give it the size of the array, not the last index, so get rid of c as it's unnecessary and replace your declaration of x with:
As you want a size 1000 array, not a size 999 array! 999 is the index of the final element, but not the size.
And close your file right after the loop that gets all the elements, it makes almost no difference with this program but as you want good practice, good practice is closing a file as soon as you're done so that other programs can use it!