/* * Write a program called normalise.cc that: * * 1. Reads in from the user a sequence of 5 floats and puts them in an array * 2. Computes and displays the maximum number in the sequence * 3. Divides each element of the array by the maximum number in the sequence * 4. Displays the new array * * For example: * * Enter the 5 numbers separated by spaces: * 2 5 8 20 15 * The maximum value is 20 * The normalised array is: * 0.1 0.25 0.4 1 0.75 */ #include using namespace std; const int N = 5; int main() { float numbers[N], max; int i; // Read in the numbers cout << "Enter the 5 numbers separated by spaces:" << endl; for (i = 0; i < N; i++) { cin >> numbers[i]; } // Compute the maximum entered max = numbers[0]; for (i = 0; i < N; i++) { if (numbers[i] > max) { max = numbers[i]; } } // Show the maximum cout << "The maximum value is " << max << endl; // Normalise for (i = 0; i < N; i++) { numbers[i] /= max; } // Show the new array cout << "The normalised array is:" << endl; for (i = 0; i < N; i++) { cout << numbers[i] << " "; } cout << endl; return (0); }