MARK C. answered 11d
C++ Tutor | Data Structures & Algorithms | 20+ Years Coding Experience
How it works:
- Read the count of values (n)
- Read all n floating-point values into a vector
- Find the maximum value while reading
- Set output precision to 2 decimal places
- Divide each value by the maximum and output
Example: Input: 5 30.0 50.0 10.0 100.0 65.0
Output: 0.30 0.50 0.10 1.00 0.65
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<double> values(n);
double maxValue = 0.0;
// Read all values and find maximum
for (int i = 0; i < n; i++) {
cin >> values[i];
if (values[i] > maxValue) {
maxValue = values[i];
}
}
// Set output format to 2 decimal places
cout << fixed << setprecision(2);
// Normalize and output each value
for (int i = 0; i < n; i++) {
cout << values[i] / maxValue << " ";
}
cout << endl;
return 0;
}