Plus Minus

Sort by

recency

|

209 Discussions

|

  • + 0 comments
    #include <bits/stdc++.h>
    using namespace std;
    
    void plusMinus(vector<int> arr) {
        int n = arr.size(), pos = 0, neg = 0, zero = 0;
        for (int x : arr) pos += x > 0, neg += x < 0, zero += x == 0;
        cout << fixed << setprecision(6) << (double)pos / n << endl << (double)neg / n << endl << (double)zero / n << endl;
    }
    
    int main() {
        int n; cin >> n;
        vector<int> arr(n);
        for (int i = 0; i < n; i++) cin >> arr[i];
        plusMinus(arr);
        return 0;
    }
    
  • + 1 comment

    how to solve this plus minus problem

  • + 0 comments

    typescript/javascript

    console.log((arr.filter(el => el > 0).length/arr.length).toFixed(6)); console.log((arr.filter(el => el < 0).length/arr.length).toFixed(6)); console.log((arr.filter(el => el === 0).length/arr.length).toFixed(6));

  • + 3 comments
    public static void plusMinus(List<int> arr)
        {
            int n = arr.Count;
            if (n > 0 && n <= 100)
            {
                int positives = arr.Count(x => x > 0);
                int negatives = arr.Count(x => x < 0);
                int zeros = arr.Count(x => x == 0);
                
                // Calculate and print ratios with 6 decimal places
                Console.WriteLine("{0:F6}", (decimal)positives / n);
                Console.WriteLine("{0:F6}", (decimal)negatives / n);
                Console.WriteLine("{0:F6}", (decimal)zeros / n);
            }
        }
    
  • + 0 comments

    **