hackerrank algorithm problem solution

#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { int n; int pos=0; int neg=0; int non=0; cin >> n; vector<int> arr(n); for(int arr_i = 0;arr_i < n;arr_i++) { cin >> arr[arr_i]; if(arr[arr_i]>0) { pos++; }else if(arr[arr_i]<0) { neg++; }else { non++; } } cout << (double)pos/(double)n << endl << (double)neg/(double)n << endl << (double)non/(double)n << endl; return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.