Plus Minus

Sort by

recency

|

207 Discussions

|

  • + 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));

  • + 0 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

    **

  • + 0 comments

    def plusMinus(arr): n = len(arr) # Get the number of elements count_positive = sum(1 for x in arr if x > 0) # Count positive numbers count_negative = sum(1 for x in arr if x < 0) # Count negative numbers count_zero = sum(1 for x in arr if x == 0) # Count zeros

    # Calculate ratios
    positive_ratio = count_positive / n
    negative_ratio = count_negative / n
    zero_ratio = count_zero / n
    
    # Print results with 6 decimal places
    print(f"{positive_ratio:.6f}")
    print(f"{negative_ratio:.6f}")
    print(f"{zero_ratio:.6f}")
    

    if name == 'main': n = int(input().strip()) # Read the number of elements arr = list(map(int, input().rstrip().split())) # Read the array elements

    plusMinus(arr)  # Call the function
    
  • + 0 comments
    def plusMinus(arr):
        positives, negatives, zeros = 0, 0, 0
        total = len(arr)
        for i in arr:
            if i < 0:
                negatives += 1
            elif i == 0:
                zeros += 1
            else:
                positives += 1
        print(f"{(positives/total):.6f}")
        print(f"{(negatives/total):.6f}")
        print(f"{(zeros/total):.6f}")