You are viewing a single comment's thread. Return to all comments →
c++20
void plusMinus(vector<int> arr) { size_t nPositive = 0; size_t nNegative = 0; size_t nZero = 0; for(int val : arr){ if(val > 0){ nPositive += 1; } else if(val < 0){ nNegative += 1; } else{ nZero += 1; } } double fracPositive = nPositive/static_cast<double>(arr.size()); double fracNegative = nNegative/static_cast<double>(arr.size()); double fracZero = nZero/static_cast<double>(arr.size()); std::cout << std::fixed; std::cout << std::setprecision(6); std::cout << fracPositive << std::endl; std::cout << fracNegative << std::endl; std::cout << fracZero << std::endl; }
Seems like cookies are disabled on this browser, please enable them to open this website
Plus Minus
You are viewing a single comment's thread. Return to all comments →
c++20