We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int main() {
// Step 1: Read the number of elements (not actually used, we just need the list)
int n;
cin >> n;
// Step 2: Read the list of numbers into a vector
vector<int> nums(n);
for (int i = 0; i < n; ++i) {
cin >> nums[i];
}
// Step 3: Calculate the average
double sum = 0;
for (int num : nums) {
sum += num;
}
double average = sum / n;
// Step 4: Find the minimum number
int min_val = *min_element(nums.begin(), nums.end());
// Step 5: Output the results
// Print the average rounded to 1 decimal place
cout << fixed << setprecision(1) << average << endl;
// Print the average rounded to the nearest whole number
cout << round(average) << endl;
// Print the smallest number
cout << min_val << endl;
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Day 0: Mean, Median, and Mode
You are viewing a single comment's thread. Return to all comments →
include
include
include
include // For controlling the output format
using namespace std;
int main() { // Step 1: Read the number of elements (not actually used, we just need the list) int n; cin >> n;
}