I'm reading the book "Cracking the Coding Interview" which contains several examples of algorithms in C. I'd like to make programs which implement these algorithms and run them as I go along.
One such algorithm is "Min and Max 1" (from the "Big O" chapter):
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for (int x : array) {
if (x < min) min = x;
if (x > max) max = x;
}
I've attempted to 'write a program around this' as follows:
#include<stdio.h>
int array[5] = [1, 3, 2, 5, 4];
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
int main(void):
{
for (int x : array) {
if (x < min) min = x;
if (x > max) max = x;
}
printf("The minimum is %i", min)
printf("The maximum is %i", max)
}
However, if I try to compile and run this I get the error: expected identifier before numeric constant int array[5] = [1, 3, 2, 5, 4];
. How would I correctly implement this algorithm for this example input array?