// Recapping 1D arrays! // Problem: A user is asked to enter 5 numbers. We will // then go through these numbers and find the highest // number and output what that number is to the // user. /* */ #include #define MAX 5 int main(void) { int max_number; // Declare an array to store the numbers that the user will enter int array[MAX]; // Scan in the numbers into the array to initialise it // and don't forget to do some error checking! for(int i = 0; i < MAX; i++) { printf("Please enter a number: "); scanf("%d", &array[i]); } // Let's pretend the numbers are 1, 2, 4, 6, 8 // Now check for highest number and output it: max_number = array[0]; for(int i = 0; i < MAX; i++) { if(array[i] > max_number) { max_number = array[i]; } } printf("The highest number is %d\n", max_number); return 0; }